How to repeat an ArrayList array of an array of objects using JSTL?

I have a list of objects array like this.

List<Object[]> reqUserDetails = new ArrayList<Object[]>(); 

Now I need to iterate this list and accept values ​​such as Object [0], Object [1] .... How to do it using JSTL?

+5
source share
2 answers

The general syntax is to name it,

 <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> 

since it contains an array of objects inside a List . so the external list will hold the Object[] , which you need to repeat again.

Hope this helps!

+3
source

From the controller :

 List<Object[]> reqUserDetails = new ArrayList<Object[]>(); request.setAttribute("reqUserDetails", reqUserDetails); 

And from the viewing side, you can iterate over the list according to your requirements.

  <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> 
+1
source

Source: https://habr.com/ru/post/1212411/


All Articles