5

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?

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

Can you please undo the down vote @SanKrish? I guess you did it and I have also updated my answer.
haha.. Okey. I didn't notice his array of object at first time. :)
1

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>

5 Comments

But how to iterate a list of object array (List<Object[]>)?
Warning !! His list contains Array of objects which shouldnt be iterated in this manner
Okey, @Usr1123, You can iterate again as per your requirement. It is something like for loop. I have updated my answer.
Why down vote @SanKrish? Haha, If he knows how to iterate list first then have can handle any kind of array or any level of list. I guess, You should comment here or can update this And it is so called "helping zone "
Dont feed direct code , help with some descriptions . which would help the OP .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.