Reputation:
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.
Upvotes: 2
Views: 15962
Reputation: 2624
I think this will help you:
<% int variable = 0 %>
<s:iterator value="results">
<s:property value="someIntValue" var="number"/>
<% variable += ${number} %>
</s:iterator>
<%= variable %>
Upvotes: 2
Reputation: 1013
<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.
Upvotes: 6