This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 60804
    
  65

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]
 
jQuery in Action, 2nd edition
 
subject: Iterate thru list in JSPs
 
Similar Threads
sort by two fields
KHALIDS book-CONTRADICTION on GC
question about passing parameters by value or by reference
Passing Table values to action class