File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Looping over nested list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Looping over nested list" Watch "Looping over nested list" New topic

Looping over nested list

Cemil Ozdemir

Joined: Nov 23, 2006
Posts: 11
Hi all,

I am new to jsp so i have a question i hope someone can help me with.

I have a ArrayList (1) that contains ArrayLists(2).

The latter ArrayList contains ValidationResult objects.

I am using Spring, and i add the first ArrayList with the name validationGroup:
modelData.put("validationGroup", validationGroup);

On my jsp page i want to iterate over ArrayList (1) and retrieve the ArrayList(2), so i can iterate over the ValidationResult objects in ArrayList(2).

This is how my code looks like now:
<c:forEach var="vGroup" items="${validationGroup}" varStatus="counter">
<c:if test="${not empty vGroup}">
<c:forEach var="gr" items="${vGroup.validationResult}" varStatus="counter">
<tr class="row<cut value="${counter.count % 2 + 1}" />" valign="top"

But this is wrong.

How do i iterate over a nested ArrayList that contains ValidationResult objects ?

Hope somone can help me...

Best Regards
[ November 23, 2006: Message edited by: Cemil OZdemir ]
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

In the second forEach, items should be "vGroup", not "vGroup.validationResult"

[My Blog]
All roads lead to JavaRanch
I agree. Here's the link:
subject: Looping over nested list
It's not a secret anymore!