This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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


JavaRanch » Java Forums » Java » JSP
Bookmark "Iterate thru list in JSPs" Watch "Iterate thru list in JSPs" New topic
Author

Iterate thru list in JSPs

Su nan
Greenhorn

Joined: Jun 19, 2012
Posts: 4
Hi,
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
Marshal

Joined: Jan 10, 2002
Posts: 61298
    
  66

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]
 
GeeCON Prague 2014
 
subject: Iterate thru list in JSPs