tags:

views:

1357

answers:

2

I have an s:iterator tag like the following

<s:iterator value="results">
    <s:property value="someIntValue"/>
</s:iterator>

At the end of this loop i want the total of someIntValue. In plain java I would do something like this

variable += someIntValue

but can this be done inside the struts2 tag? I looked at documentation for s:set tag but was not able to figure out how to achieve this.

+1  A: 
<s:iterator value="users" status="itStatus">
    <li>
       <s:property value="#itStatus.count" />
    </li>
</s:iterator>

Count should give you the value you are looking for. More detail: link text

From struts in action book:

Sometimes it’s desirable to know status information about the iteration that’s taking place. This is where the status attribute steps in. The status attribute, when defined, provides an IteratorStatus object available in the ActionContext that can provide simple information such as the size, current index, and whether the current object is in the even or odd index in the list. The IteratorStatus object can be accessed through the name given to the status attribute.

samsina
that is not what I was asking. I am not concerned with the 'iteration number'. I am more concerned with the value coming from getSomeIntValue in the action class. Every iteration this value might be different and I want to count all those values. for example for 3 iterations value for someIntValue is: iter1->10, iter2->20, iter3->30. then at the end I want total which would be 60.
A: 

Hi,

did you ever get an answer to your question? I'm looking to do exactly the same in my app