aspose file tools*
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
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Nested C:forEach varStatus ??" Watch "Nested C:forEach varStatus ??" New topic
Author

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
slist.add(s1);
slist.add(s2);
request.setAttribute("slist",slist);

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
Dude,

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}
<BR>
</c:forEach>
</c:forEach>

hth.
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é
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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: http://aspose.com/file-tools
 
subject: Nested C:forEach varStatus ??