• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Iterate thru list in JSPs

 
Su nan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic