Struts 2 : Tag with status object

The <s:iterator> tag is widely used on UI (jsp)  to iterate some collection returned by any action.


<table class="facebookFriendList">
   <tr class="even">
       <td><b>UserName</b></td>
       <td><b>ProfileImage</b></td>
    </tr>
   <s:iterator value="facebookFriendList" status="rowStatus">
     <tr class="<s:if test="rowStatus.odd == true ">odd</s:if><s:else>even</s:else>">
         <td><s:property value="userName" /></td>
         <td><s:property value="profileImageURL" /></td>
     </tr>
     </s:iterator>
</table>

We use the iterator tag to iterator over the collections. See OGNL expression #statusName.

Properties of the IteratorStatus object.
----------------------------------------------------------------------
Name Return Type Description
----------------------------------------------------------------------
index  int           zero-based index value.
count  int           index + 1
first     boolean   will return true if it is the first element
last     boolean   will return true if it is the last element
even  boolean   will return true if the count is an even number.
odd    boolean   will return true if the count is an odd number.
modulus  int        will take an int value and return the modulus of count. 
------------------------------------------------------------------------

Comments

Popular posts from this blog

Read Images from a xlsx file using Apache POI

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'

How to create mail message in FRC822 format