views:

5

answers:

2

Hi. I have an iterate and i want to calculate sum of the values like this :

 <s:iterator value="myValues" status="myStatus">
     <s:property value="value" />
 </s:iterator> 
 <s:property value="total.here" /> 

I want to show the sum of "value" in "total.here". Sorry for my bad english. Thank you very much.

+1  A: 

Assuming myValues is an array or a list of integral values accessible from your action:

<s:set var="total" value="%{0}" />
<s:iterator value="myValues">
     <s:set var="total" value="%{top + #attr.total}" />
</s:iterator> 
<s:property value="%{'' + #attr.total}" /> 
Samuel_xL
A: 

Samuel_xL's answer is right. But, in general, if you can edit your action class, I'd advice to make the calculation there instead of doing it in jsp.

leonbloy