Compute in struts 2 tags?

I have an iteration, and I want to calculate the sum of the following values:

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

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

+3
source share
2 answers

Assuming myValues - an array or a list of integral values available from your actions:

<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}" /> 
+4
source

Answer Samuel_xL is right. But, in general, if you can edit your action class, I would advise doing calculations there instead of doing it in jsp.

+1
source

Source: https://habr.com/ru/post/1768592/


All Articles