hieund
hieund

Reputation: 31

calculate in struts 2 tag?

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.

Upvotes: 3

Views: 5929

Answers (2)

leonbloy
leonbloy

Reputation: 75896

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.

Upvotes: 1

KeatsPeeks
KeatsPeeks

Reputation: 19327

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}" /> 

Upvotes: 4

Related Questions