Search code examples
javajspjstl

Jsp iterate through object list


I'm having troubles iterating with jsp trough list/lists. Here is my object class called Table:

public class Table{

private String name;
private List<String> columns;
private List<Row> rows;

... continuing with getters and setters nothing more here

}

In my Row class I have just Strings(ex: String name), no lists no nothing.

Currently I have some List<Table> and I'm iterating trough it like this:

<c:forEach var='table' items='${requestScope.tables}'>
        <c:out value="{table.name}"></c:out>
</c:forEach>

Just for testing .. and it prints just {table.name} x times(the correct number of table objects in the table list).

My final goal is something like this (pseudo code):

for each table in table list
     print name
     for each column in colum list
         print column
     end column list for
     for each Row in row list
         print Row.name
     end row list for
end table list for

Could someone help me out with syntax?


Solution

  • <c:forEach var="table" items='${requestScope.tables}'>
            <c:out value="${table.name}"></c:out>
    
            <c:forEach var="column" items='${table.columns}'>
               <c:out value="${column}"></c:out>
            </c:forEach>
    
            <c:forEach var="row" items='${table.rows}'>
               <c:out value="${row.name}"></c:out>
            </c:forEach>
    
    </c:forEach>