• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

varstatus in nested foreach

 
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.
 
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.
 
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.
 
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.
 
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic