• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL iteration over 2 or more items  RSS feed

 
alex reznik
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
i would like to use a forEach loop to iterate over two sets of items, similarly if i were to write a for loop like this:
for(int i=0, int j=0; i<10, j<10;i++, j++)...
how would i do this in JSTL?
Thank You,
Alex
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by alex reznik:
Hello,
i would like to use a forEach loop to iterate over two sets of items, similarly if i were to write a for loop like this:
for(int i=0, int j=0; i<10, j<10;i++, j++)...
how would i do this in JSTL?
Thank You,
Alex

Alex also asked this question on the taglibs-user@jakarta.apache.org mailing list. In case my answer there is useful to anyone else, here it is:
On Mon, 15 Jul 2002, Alex Reznik wrote:
> If i were to iterate over two sets of parameters, is there a way to specify
> their values within one forEach loop?
It depends on what you really want to do. You can iterate over numbers
and apply them as indices over two arrays or List objects, like this:
<c:forEach var="i" begin="0" end="${end}">
   <cut value="${a[i]}" />
   <cut value="${b[i]}" />
</c:forEach>
Or you can iterate over one array and use 'count' from 'varStatus' as the
index into another:
<c:forEach items="${a}" var="aItem" varStatus="s">
   <cut value="${a}" />
   <cut value="${b[s.count]}" />
</c:forEach>
If you're looking for something else, please feel free to clarify. Hope
this helps,
[ July 16, 2002: Message edited by: Shawn Bayern ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!