my dog learned polymorphism
The moose likes JSP and the fly likes Iterate thru list in JSPs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Iterate thru list in JSPs" Watch "Iterate thru list in JSPs" New topic

Iterate thru list in JSPs

Su nan

Joined: Jun 19, 2012
Posts: 4
I am working on a jsp where I need to populate a table with the list I am retrieving from controller.
I have List<Object1> where List<Object2> is a member of Object1.
In my jsp, I have a table with 'X' no of rows and 'Y' no. of columns.

List<Object1> spans across columns and List<Object2> spans across rows for the particular column of its parent Object1.
Below is how my table needs to be like:

List<Object1>.get(0) List<Object1>.get(1) List<Object1>.get(2)
listObj2.get(0) listObj2.get(0) listObj2.get(0)
listObj2.get(1) listObj2.get(1) listObj2.get(1)
listObj2.get(2) listObj2.get(2) listObj2.get(2)
listObj2.get(3) listObj2.get(3) listObj2.get(3)

Can anyone help me with how to implement this in jsp.
I am familiar with iterating thru a single list in JSPs using <c:forEach /> tag to display across columns in a single row (or) across rows in single column.
But stuck up with this.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63351

Just as with 2D constructs in Java code, you need nested loops. So you'd use an outer forEach tag to iterate through the rows, and a nested forEach to iterate through the columns for each row.

Give the code a try and post back with any questions.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Iterate thru list in JSPs
It's not a secret anymore!