Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate over a list of lists in jstl?

Tags:

java

jsp

jstl

I have List in this format :

List<List<Obj>> l3 = new ArrayList<List<Obj>>();

Obj contains a method called getVal.

How can I output the value of getVal for each Obj ?

I can iterate over a List using :

<c:forEach var="mylist" items="${mylist}">

    <c:out value="${mylist.val}"></c:out>

    </c:forEach>

But how do I get the values contained in a list of lists ?

like image 929
blue-sky Avatar asked Dec 26 '22 09:12

blue-sky


1 Answers

Just like you would do it in Java - with nested loops:

<c:forEach var="innerList" items="${mylist}">
    <c:forEach var="obj" items="${innerList}">
        <c:out value="${obj.val}"></c:out>
    </c:forEach>
</c:forEach>
like image 178
Tomasz Nurkiewicz Avatar answered Feb 09 '23 03:02

Tomasz Nurkiewicz