开发者

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&g开发者_Python百科t; 
 <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.


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'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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜