Reputation: 169
I have a list of object array like this.
List<Object[]> reqUserDetails = new ArrayList<Object[]>();
Now I have to iterate this list and take values like Object[0],Object[1].... How can I do this using JSTL?
Upvotes: 5
Views: 13825
Reputation: 8207
The general syntax is to itearate it like ,
<c:forEach items="${outerList}" var="innerList">
<c:forEach items="${innerList}" var="item">
// Print your object here
</c:forEach>
</c:forEach>
and in your case ,
<c:forEach items="${reqUserDetails}" var="firstVar">
<c:forEach items="${firstVar}" var="secodVar"> // firstVar will hold your object array
<c:out value="${secondVar.field1}" /> // on iterating the object array
</c:forEach>
</c:forEach>
as it contains array of objects
inside the List
. so the outerList will hold the Object[]
which you need to iterate again.
Hope this helps !!
Upvotes: 4
Reputation: 1817
From controller:
List<Object[]> reqUserDetails = new ArrayList<Object[]>();
request.setAttribute("reqUserDetails", reqUserDetails);
And from view side, you can iterate your list as per your requirement.
<c:forEach items="${reqUserDetails}" var="objectList">
<c:forEach items="${objectList}" var="object">
<tr>
<td>${object.field1}</td>
<td>${object.field2}</td>
<td>${object.field3}</td>
........
</tr>
</c:forEach>
</c:forEach>
Upvotes: 1