You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Antonio Gallardo <ag...@agssa.net> on 2004/02/04 09:37:47 UTC

[JXTemplate] Sum values inside

Hi:

I am trying to get the sum of some values inside 2 <jxForEach>. Here is
the code:

<jx:set var="total" value="${0}"/>
<jx:set var="costo" value="${0}"/>
<jx:forEach var="activity" items="${bean.planActivityList}">
  <jx:forEach var="item" items="${activity.planCostList}">
    <jx:set var="total" value="#{item.pco_total + $total}"/>
    <jx:set var="cost" value="#{item.pco_cost + $cost}"/>
  </jx:forEach>
</jx:forEach>
<td><jx:formatNumber value="#{$total}"/></td>
<td><jx:formatNumber value="#{$cost}"/></td>
<td><jx:formatNumber value="#{$total - $cost}"/></td>

The problem is that this always return 0 values.

What I am doing wrong?

Best Regards,

Antonio Gallardo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [JXTemplate] Sum values inside

Posted by Christopher Oliver <re...@verizon.net>.
Try this:

<jx:set var="total" value="${0}"/>
<jx:set var="cost" value="${0}"/>
<jx:forEach var="activity" items="${bean.planActivityList}">
  <jx:forEach var="item" items="${activity.planCostList}">
    <jx:set var="total" value="${item.pco_total + total}"/>
    <jx:set var="cost" value="${item.pco_cost + cost}"/>
  </jx:forEach>
</jx:forEach>
<td><jx:formatNumber value="${total}"/></td>
<td><jx:formatNumber value="${cost}"/></td>
<td><jx:formatNumber value="${total - cost}"/></td>


or if you insist on using XPath:

<jx:set var="total" value="#{0}"/>
<jx:set var="cost" value="#{0}"/>
<jx:forEach var="activity" items="#{bean/planActivityList}">
  <jx:forEach var="item" items="#{$activity/planCostList}">
    <jx:set var="total" value="#{$item/pco_total + $total}"/>
    <jx:set var="cost" value="#{$item/pco_cost + $cost}"/>
  </jx:forEach>
</jx:forEach>
<td><jx:formatNumber value="#{$total}"/></td>
<td><jx:formatNumber value="#{$cost}"/></td>
<td><jx:formatNumber value="#{$total - $cost}"/></td>


But if your data consists of Java beans (as in this case) I recommend 
you stick with Jexl as the expression language.

HTH,

Chris

Antonio Gallardo wrote:

>Hi:
>
>I am trying to get the sum of some values inside 2 <jxForEach>. Here is
>the code:
>
><jx:set var="total" value="${0}"/>
><jx:set var="costo" value="${0}"/>
><jx:forEach var="activity" items="${bean.planActivityList}">
>  <jx:forEach var="item" items="${activity.planCostList}">
>    <jx:set var="total" value="#{item.pco_total + $total}"/>
>    <jx:set var="cost" value="#{item.pco_cost + $cost}"/>
>  </jx:forEach>
></jx:forEach>
><td><jx:formatNumber value="#{$total}"/></td>
><td><jx:formatNumber value="#{$cost}"/></td>
><td><jx:formatNumber value="#{$total - $cost}"/></td>
>
>The problem is that this always return 0 values.
>
>What I am doing wrong?
>
>Best Regards,
>
>Antonio Gallardo
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org