tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Cooper <mart...@apache.org>
Subject RE: What is the method of direct acces to an array element?
Date Fri, 25 Jun 2004 05:57:18 GMT


On Thu, 24 Jun 2004, Wendy Smoak wrote:

>
>> From: Sergei P. Volin [mailto:s.volin@ttk.ru]
>> I have a set of arrays of the same length and i want to
>> iterate over all of them in a turn.
>> So what is the best practice to do this?
>> Is there any direct method of direct acces to the element of an array?
>> Like this: <c:out value="$myArray[i]">
>
> Are you sure this is the best design?  If the arrays belong together,
> then they probably shouldn't be lying around loose.  Are they properties
> of some object?
>
> If this is the best design (or you can't change it), I think you can use
> the 'varStatus' of <c:forEach> to address the other arrays.  Off the top
> of my head, and probably not quite correct...
>
> <c:forEach items="${firstArray}" var="myItem" varStatus="myLoopIndex">
>    <c:out value="${myItem}"/>
>    <c:out value="${secondArray[myLoopIndex]}"/>
>    <c:out value="${thirdArray[myLoopIndex]}"/>
> </c:forEach>
>
> It might need single quotes around 'myLoopIndex'.  Or not, play around
> with it and see what works!

At the very least, you'll want to change the 'varStatus' value to 'status' 
and change the 'myLoopIndex' usage to 'status.index'. The 'varStatus' 
attribute exposes a structure rather than an index.

--
Martin Cooper

>
> --
> Wendy Smoak
> Application Systems Analyst, Sr.
> ASU IA Information Resources Management
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message