This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Nested C:forEach varStatus ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Nested C:forEach varStatus ??" Watch "Nested C:forEach varStatus ??" New topic

Nested C:forEach varStatus ??

Rajesh Vijaya
Ranch Hand

Joined: Oct 18, 2005
Posts: 48
i have two string arrays

in servlet

String [] s1 = {"A","B","C"};
String [] s2= {"X","Y","Z"};

java.util.List slist = new java.util.ArrayList

Now i forward the request to a jsp

in Jsp

I'm using C:forEach tag.... i want the output to be

1 A
2 B
3 C
4 X
5 Y
6 Z

how i can use the varStatus to get the total count !!!

Rajesh <br /> <br />SCJP1.4 SCWCD1.4 SCBCD 1.3 ,SCDJWS(Preparing..)<br /> <br />There is no free will.It is the phenomenon bound by cause and effect.But there is something behind will which is free---Swami Vivekananda...
Mike Pandey
Ranch Hand

Joined: Dec 05, 2005
Posts: 62

To get the desired output as u have mentioned u'll have to nest two <c:forEach> tags.

<c:forEach var="outer" items="${slist}" >
<c:forEach var="inner" items="${outer}" varStatus="num">
Count is ${num.count} Item is ${inner}

Humble reqst to Guys to pls address the query i posted.
Mike Pandey
Ranch Hand

Joined: Dec 05, 2005
Posts: 62
Hey man ...Apologies for missing out on the o/p u desired .
In your case you wud need to have the old "scripting along with JSTL
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

Not sure you can, because I think that you'll need to keep track of the size of the lists you've already printed.
Why don't you use a different variable ?

[My Blog]
All roads lead to JavaRanch
Rajesh Vijaya
Ranch Hand

Joined: Oct 18, 2005
Posts: 48
thanks for the code ...Satau

since there is relationship between items of the inner Foreach and the var of the outer Foreach i thought there might be relationshiop between their varStatus also.....
I agree. Here's the link:
subject: Nested C:forEach varStatus ??
It's not a secret anymore!