• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

varstatus in nested foreach

 
osman cinar eren
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I have a list whose elements are arrays. I try to display each element in these arrays with a number in front of them. HFSJ shows the varstatus usage for a single foreach. What about for a nested one?
Any ideas?

<c:forEach var="array" items="${list}" varStatus="count">
<c:forEach var="element" items="${array}" varStatus="count2">
(NO)${element}<br>
</c:forEach>
</c:forEach>

array1 = "dog","cat"
array1 = "peach","apple"
Expected result:
1. dog
2. cat
3. peach
4. apple

thanks in advance.
best regards.
 
Serghei Jelauc
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this one:

 
osman cinar eren
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is not a solution:
1.
2.
1.
2.
 
Ragu Ram
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not much familiar with EL but i guess this might help
 
Serghei Jelauc
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you want? Can you explain more detailed?
[ May 16, 2005: Message edited by: Serghei Jelauc ]
 
osman cinar eren
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

if there are N elements in the first collection, and there are M elements in each of the inner collections, I want to see such an output:

1. 1. inner collection's 1. element
2. 1. inner collection's 2. element
.
.
.
M. 1. inner collection's Mth element
M+1 2. inner collection's 1. element
.
.
.
.

is it clear?
A counter that holds all of the loops not each individual as we have with varStatus.

using index is good, but what if the number of the elements in the inner collections is variable.
 
Kumar J
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
declare a temp var...set it as a attribute preferably...just for your temporary calculations...keep incrementing the var each time the inner loop is executed.

bye
 
Serghei Jelauc
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about this code:
 
osman cinar eren
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
re Serghei:

this is a good way of indexing, but not what i look for.
I have looked at the properties of the class of the varStatus. I could not see any value for my problem.

So this thread is closed.
thanks to all the repliers.

best regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic