Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "status" in <s:iterator> do?

I am using the following command to display values from 'userList'

<s:iterator value="userList" status="rowStatus">
  <tr class="even"> 
    <td><s:property value="tweet_id" /></td>
    <td><s:property value="message" /></td>
    <td><s:property value="created" /></td>
  </tr>
</s:iterator>

What is the use of status="rowStatus" in this command?

like image 779
Siddharth Avatar asked Mar 02 '26 18:03

Siddharth


1 Answers

From docs.

The iterator tag can export an IteratorStatus object so that one can get information about the status of the iteration, such as:

index: current iteration index, starts on 0 and increments in one on every iteration
count: iterations so far, starts on 1. count is always index + 1
first: true if index == 0
even: true if (index + 1) % 2 == 0
last: true if current iteration is the last iteration
odd: true if (index + 1) % 2 == 1

Example

   <s:iterator status="rowStatus" value='{0, 1}'>
      Index: <s:property value="%{#rowStatus.index}" /> <br />
      Count: <s:property value="%{#rowStatus.count}" /> <br />  
   </s:iterator>

will print

  Index: 0
  Count: 1
  Index: 1
  Count: 2

In your userList

userList count = 1 to userList.size();
userList index = 0 to userList.size() - 1;
like image 106
Ken de Guzman Avatar answered Mar 05 '26 20:03

Ken de Guzman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!