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

Popular posts from this blog

Android: where to run keytool command in android

Can not connect to git using ssh (Permissions 0644 for '/root/.ssh/id_rsa' are too open.

Upload file on Google cloud storage using Java servlet on google app engine