Thanks! That helps a lot.

-Jack

Paul Libbrecht wrote:

Jack Lund wrote:

Hi. Sorry if this is a newbie question, but I can't find it on the mailing lists or anywhere.

I'm using Jelly within Maven, and I'm trying to access elements in two parallel arrays. My script looks something like this:

     <u:tokenize var="names" delim=",">${foo.names}</u:tokenize>
     <u:tokenize var="classes" delim=",">${foo.classes}</u:tokenize>
     <j:forEach items="${names}" var="name", indexVar="i">
<ant:echo>name = ${name}, class = ${classes}[${i}]</ant:echo>
     </j:forEach>

Obviously, the second part of my ant:echo line doesn't work, but my questions are: 1) How do you access an item in an array in Jelly - I can't seem to find anything that says what the syntax is

As in java... the following works:
<j:jelly xmlns:j="jelly:core">
 <j:set var="x" value="xx"/>
 <j:set var="x" value="${x.toCharArray()}"/>
 ${x[0]}
</j:jelly>
(i.e. its output is x)

2) Is this the best way to handle parallel arrays in Jelly?

Now, be careful util:tokenize doesn't produce arrays! It produces a List... so
${classes[i]} might not work but ${classes.get(i)} does work.
I think the way you've done with the index is the way to process parallel arrays. You could also use an iterator!

paul

PS: so many folks forget that jelly is not in an opaque bizarre language but just in java.... having problems with object x, try ${x.getClass()}... then use the appropriate methods!

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to