cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Quinn <jer...@apache.org>
Subject RFC: Setting Currency on FormattingDecimalConvertor
Date Mon, 28 Jul 2008 12:05:44 GMT
Hi All

Coming out of my work to add client-side datatype-validation to CForms  
Fields, I am proposing to add a new method and configuration option to  
o.a.c.forms.datatype.convertor.FormattingDecimalConvertor, to allow  
the setting of a specific currency, when the 'currency' variant is used.

ATM, there is no option to set the currency, so the currency is  
automatically selected by the locale of the user. (Something that  
could loose eCommerce sites some money :)

With this change, you'd have two different ways to setup the currency :

In the CForms Model :
<fd:datatype base="decimal">
   <fd:convertor variant="currency" currency="GBP"/>
</fd:datatype>

Or in Flow :
var model = form.getModel();
model.dieselprice = new Packages.java.math.BigDecimal("1000000");
form 
.getChild 
("dieselprice").getDatatype().getConvertor().setCurrency("GBP");

The number then gets displayed using that currency, but in the locale  
of the user :

eg.
en_GB: £1,000,000.00
nl_NL: GBP 1.000.000,00
fr_FR: 1 000 000,00 GBP
de_CH: GBP 1'000'000,00
hi_IN: GBP १,०००,०००.००

etc.

(You wouldn't /believe/ how many ways there are of showing a number!!!)

As an aside ..... in the near future (I hope!) when the new validating  
cocoon.forms.NumberField is working properly, the user will see the  
field populated with the full formatted string for their locale. When  
they click to edit, the content switches to an easier-to-edit format :

eg.
view: £1,000,000.00
edit: 1000000.00

The field validates as you type, giving you real-time feedback.
When you have finished editing, the field reverts to it's full-format  
display mode.

Your feedback would be welcome.

regards Jeremy

NB. Don't get confused by the term 'convertor' ..... this is  
converting between a Java Number Object and a locale formatted String,  
it is not converting from one currency to another (!!).


Mime
View raw message