On Feb 19, 2010, at 10:22 AM, Jean-Francois Veillette wrote:

To fix it I had to overwrite the validator "validatePourcentageEstime(Object o)" and set the scale of the BigDecimal received.
I tought that my formatter was doing enough, defined like so:
DecimalFormat formatPourcent = formatPourcent = new DecimalFormat("0.0");
        formatPourcent.setMinimumFractionDigits(2);
        formatPourcent.setMultiplier(100);
        formatPourcent.setMaximumFractionDigits(4);

I'm sure I miss something and doesn't need to overwrite validatePourcentageEstime, how do you do ?

Ah ha!  That formatter is NOT doing what you think it is:

From the JavaDocs:
Currently, the only classes that parse returns are Long and Double, but callers should not rely on this.

It is returning a Double and KVC (or EOF?) is creating from that. You either need to to set the scale in the validate method, or create a BigDecimalFormat that does the right thing. So that explains why you were getting the SQL error.


Is it changed in java 1.6 ? because in 1.5:
http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html#parse(java.lang.String,%20java.text.ParsePosition)
in the parse definition we have:
• If isParseBigDecimal() is true, values are returned as BigDecimal objects. The values are the ones constructed by BigDecimal.BigDecimal(String) for corresponding strings in locale- independent format. The special cases negative and positive infinity and NaN are returned as Double instances holding the values of the corresponding Double constants.

I just Googled DecimalFormat, must have gotten an old version.



I'll first try to add:
        formatPourcent.setParseBigDecimal(true);
and if it doesn't work, I'll keep the validate method.

Thanks again for the pointer !

- jfv



--
Chuck Hill             Senior Consultant / VP Development

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects







_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to