POJO
POJO

Reputation: 11

How to calculate sum in nested iteration in Struts2 tags

Total spots is not printed in the span

<s:set var="totalSpots" value="0"/>
     <s:iterator var="spotSchedule" value="spotSchedules">
       <s:set var="totalSpots" value="#totalSpots + %{spotSchedule.noOfSpots}" />
     </s:iterator>
<span style='cursor:pointer;text-decoration:underline;padding-left:5px;color:blue;'>
   <s:property value="#totalSpots"/>
</span>

Upvotes: 1

Views: 1493

Answers (1)

Aleksandr M
Aleksandr M

Reputation: 24396

Use # sign to reference your spotSchedule variable inside <s:iterator> tag.

<s:set var="totalSpots" value="0"/>
  <s:iterator var="spotSchedule" value="spotSchedules">
    <s:set var="totalSpots" value="#totalSpots + #spotSchedule.noOfSpots" />
  </s:iterator>
<span style='cursor:pointer;text-decoration:underline;padding-left:5px;color:blue;'>
   <s:property value="#totalSpots"/>
</span>

Upvotes: 1

Related Questions