cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antonio Gallardo <agalla...@agssa.net>
Subject Re: Calculated fields
Date Mon, 10 Apr 2006 00:46:02 GMT
Hi Simone,

Thanks for taking care of this old but very important issue. Please see 
comment below...

Simone Gianni escribió:
> Hi all,
> what about calculated fields? In a cocoon form I have a repeater, in 
> the repeater there are some numeric fields, and i need to show the sum 
> of values in these fields at the bottom of the page. This can be done 
> with fd:value-changed and some javascript or custom classes, but 
> actually since they are mentioned on Jira in the roadmap ( 
> http://issues.apache.org/jira/browse/COCOON-941 ), I need them, and 
> they are a good idea, I was wandering how to implement them.
>
> I tried prototyping something, and basically arrived to this :
>
> .. inside the repeater ..
>
> <fd:field id="items" required="true">
>  <fd:label>Items</fd:label>
>  <fd:datatype base="integer"/>
> </fd:field>
> <fd:field id="price" required="true">
>  <fd:label>Price</fd:label>
>  <fd:datatype base="double"/>
> </fd:field>
>
> <fd:calculatedfield id="subtotal" required="true" state="output">
>  <fd:label>Sub total</fd:label>
>  <fd:datatype base="double">
>     <fd:convertor type="formatting" variant="currency"/>
>  </fd:datatype>
>  <fd:algorithm type="arithmetic" operation="multiplicate">
>    <fd:triggers>items,price</fd:triggers>
>  </fd:algorithm>
> </fd:calculatedfield>
What about replacing <fd:algorithm> with something like:

 <fd:value eval="items*price"/>

>
> .... outside the repeater ...
>
> <fd:calculatedfield id="totalitems" state="output" required="true">
>  <fd:label>Total items</fd:label>
>  <fd:datatype base="integer"/>
>  <fd:algorithm type="arithmetic" operation="sum">
>    <fd:triggers>/articles/*/items</fd:triggers>
>  </fd:algorithm>
> </fd:calculatedfield>
 <fd:value eval="sum(articles.items)"/>

this will allow also to write:

 <fd:value eval="sum(articles.items*articles.price)"/>
>
> <fd:calculatedfield id="totalitemscost" state="output" required="true">
>  <fd:label>Total cost</fd:label>
>  <fd:datatype base="double">
>    <fd:convertor type="formatting" variant="currency"/>
>  </fd:datatype>
>  <fd:algorithm type="arithmetic" operation="sum">
>    <fd:triggers>/articles/*/subtotal</fd:triggers>
>  </fd:algorithm>
> </fd:calculatedfield>
 <fd:value eval="sum(articles.subtotal)"/>

In both later cases, <fd:value> should be able to know that "articles" 
is a container and hence it needs to include in the operation the whole 
set of rows from the repeater.

I think we should first define the user interface and then go into 
implementation details.

WDYT?

Best Regards,

Antonio Gallardo.

Mime
View raw message