Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the Object Index From ArrayList with JSTL

Is it possible to get the "row" index from an arraylist using JSTL?

<c:forEach items="${searchResults}" var="contact">
<div style="padding: 5px;">
${contact.firstName} ${contact.lastName}
<br>
${contact.primaryPhone}
</div>
</c:forEach>

My intention is to set a hyperlink that contains each items ID on each row so the user can click and display a popup, or another page and easily retrieve just the single object from the arraylist without going back to the database and setting another session object etc.

like image 624
ryandlf Avatar asked Nov 24 '11 04:11

ryandlf


1 Answers

Use varStatus attribute.

<c:forEach items="${searchResults}" var="contact" varStatus="loop">
  <div style="padding: 5px;">
  ${loop.index} - 
  ${contact.firstName} ${contact.lastName}
  <br>
  ${contact.primaryPhone}
 </div>
</c:forEach>
like image 174
KV Prajapati Avatar answered Sep 25 '22 23:09

KV Prajapati