struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Evans <dsev...@berndtgroup.net>
Subject Re: iterating over multiple Collections in one loop with JSTL
Date Thu, 25 May 2006 16:11:58 GMT
<c:forEach items="list1" var="list1Item" varStatus="status">
   ${list1Item}
   ${list2[status.index]}
</c:forEach>

the status variable is an instance of LoopTagStatus, which has an index
property that is set by the forEach loop.

I might favor combining the two lists (in your action) into a single
list, each element of which has a list that holds the two items from the
lists. so you'd access it like:

<c:forEach items="bothListsList" var="listItems" >
   ${listItems[0]}
   ${listItems[1]}
</c:forEach>


Dave


On Thu, 2006-05-25 at 08:28 -0700, Pat Slater wrote:
> Hi,
> Is it possible to do with JSTL something like this: 
> (Note: size of list1 and list2 are equal)
> List list1 = getList1();
> List list2 = getList2();
> for(int i=0; i<list1.size(); i++)
> {
>     MyClass1 x1 = (MyClass1)list1.get( i );
>     MyClass2 x2 = (MyClass2)list2.get( i );
> }
> ----------------------------------------------------------------------------
> I can iterate with JSTL with forEach for either of the lists separately but I need to
display both of them in the same loop. How can I do that?
> 
> 
> 			
> ---------------------------------
> Sneak preview the  all-new Yahoo.com. It's not radically different. Just radically better.



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


Mime
View raw message