webtier@glassfish.java.net

Re: JSF Converter question

From: Mikael Andersson <mail.micke_at_gmail.com>
Date: Mon, 14 Jul 2008 16:22:27 +0100

Some more information about what I'm doing.

For example:
dummy.doubleNumber = 123,000,000.10

I want to display this in millions, so I've created my own converter which
extends NumberConverter.

With only maxFractionDigits=3 the displayed value is: "123"

Then on postback I have this in my UnitNumberConverter.getAsObject()
(extends NumberConverter):

Object obj = super.getAsObject(ctx, comp, value);

Unless the "value" String contains something with a decimal point and non
zeroes the returned object is a Long.

I thought I could get around this problem by using the minFractionDigits.
But even if the value coming into getAsObject is "123.00" I get a Long
object back from the super.getAsObject call.

This seems like slightly dodgy behaviour, or perhaps I'm using it the wrong
way.

Cheers,
 micke

2008/7/14 Mikael Andersson <mail.micke_at_gmail.com>:

> Hi all
>
> When I have the following in a form and submit I get an error:
>
> <h:outputText value="Double value"/>
> <h:inputText value="#{dummy.doubleNumber}">
> <f:convertNumber maxFractionDigits="0"/>
> </h:inputText>
>
> The error is:
> value="#{dummy.doubleNumber}": Can't set property 'doubleNumber' on class
> 'backing.DummyBacking_$$_javassist_6' to value '123,000,000'.)
>
> The doubleNumber property is a Double.
>
> When debugging the NumberConverter the parsed Object seems to be a Long.
>
> Question: is this the expected behaviour?
>
> Ran into this when implementing a "UnitNumberConverter" which will divide
> the number by some unit, like 1000,000 to display numbers in for example
> millions.
>
> Cheers,
> Micke
>