I'm looking for ideas to show only last element of iterator using struts 2
i have this code :
<s:iterator value="listuser" status="userStatus">
<tr class="<s:if test="#userStatus.odd == true ">odd</s:if><s:else>even</s:else>">
<td><s:property value="nameuser" /></td>
// and others
</s:iterator>
The Struts2 Iterator Status not only provide odd and even methods, it provides also a last and first method.
<s:iterator value="listuser" status="userStatus">
<s:if test="#userStatus.last == true ">
<td><s:property value="nameuser" /></td>
</s:if>
</s:iterator>
Something like this will do the trick :
<s:if test="#userStatus.index==listuser.size()-1">
//Show the last element here
</s:if>
[UPDATE]
As per Quaternion's comment, here's how to get it in one line :
<s:set name="lastUser" value="listuser[listuser.size()-1]"/>
Above we set the last element in lastUser and here's how to use it else-where in the same page.
<s:property value="#lastUser.name"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With