<inputText value="#{mybean.adouble}" />
requires input of 5.0 (DoubleConverter does this "Double.valueOf(value)"

if you want 5,0 (where , is the decimal separator, like in Germany), you need a
numberConverter with pattern or locale.

-Matthias

On 9/13/07, Michael Heinen <[EMAIL PROTECTED]> wrote:
> Damn, I tested a little bit more and now there is another problem.
> If I enter 5.0 or 5,0 (depending on the locale) I get the following
> exception:
>
> Exception setting property Threshold: of base with class
> com.recommind.litigation.client.web.model.Category, Bean:
> com.recommind.litigation.client.web.model.Category, property:
> Threshold:, newValue: 5,newValue class: java.lang.Long method parameter
> class: java.lang.Double, argument type mismatch
>
> The NumberConverter returns a Long instead of a Double!
>
> How can I get a simple automatic NumberConversion working ?
> This is really annoying!
>
> Michael
>
>
> -----Original Message-----
> From: Michael Heinen [mailto:[EMAIL PROTECTED]
> Sent: Donnerstag, 13. September 2007 10:09
> To: MyFaces Discussion
> Subject: RE: number conversion and null values
>
> Thanks Ben, this solved the problem.
> Changing only the setter was not sufficient.
> I have to change the getter and the type also to Double, as you said.
>
> Michael
>
> -----Original Message-----
> From: Ben Smith [mailto:[EMAIL PROTECTED]
> Sent: Mittwoch, 12. September 2007 22:06
> To: MyFaces Discussion
> Subject: Re: number conversion and null values
>
> You should definitely be using Double instead of double, because
> otherwise you have no way to store it when the user leaves the field
> blank (unless the user isn't allowed to leave it blank).
>
> When you tried setTreshold(Double treshold), did you also change the
> getter to return a Double instead of a double?  I believe the setter
> and getter have to use the same type.
>
> Also, the variable you store the threshold in should be a Double too
> so that you can store the fact that the user entered nothing.
> Otherwise you would have the problem of how do you convert from a
> Double that is null to a double that cannot be null.
>
> Offtopic: the primitive/Object duality is one of the many concepts in
> Java that make it a bit inelegant.
>
> --Ben
>
> On 9/12/07, Michael Heinen <[EMAIL PROTECTED]> wrote:
> > The problem is independent of the used pattern.
> > I removed the pattern and got the same error message.
> > The NumberConverter.getAsObject returns null if the value is null or
> if
> > value.length() is 0.
> >
> >
> > I think the problem is that JSF does not find an appropriate setter
> for
> > setting null!
> >
> > I am also not sure whether the NumberConverter has to return null or 0
> > in this case, which is the default for primitive numeric values.
> >
> > Any ideas ?
> >
> >
> > -----Original Message-----
> > From: Mike Kienenberger [mailto:[EMAIL PROTECTED]
> > Sent: Dienstag, 11. September 2007 22:52
> > To: MyFaces Discussion
> > Subject: Re: number conversion and null values
> >
> > Maybe <f:convertNumber pattern="###.##"/> instead?  I'm not an expert
> > on format patterns, but doesn't 0 mean "at least one digit?"
> >
> >
> >
> > On 9/11/07, Michael Heinen <[EMAIL PROTECTED]> wrote:
> > >
> > >
> > >
> > >
> > > I have a conversion problem with doubles and null values.
> > >
> > >
> > >
> > > JSP snippet:
> > >
> > > <h:inputText
> > >
> > > value="#{!empty MyController.category&&
> > MyController.category.treshold>=0?
> > > MyController.category.treshold:''}">
> > >
> > >   <f:convertNumber pattern="##0.##"/>
> > >
> > > </h:inputText>
> > >
> > >
> > >
> > > Class Category
> > >
> > >   public double getTreshold()
> > >
> > >   {
> > >
> > >     return this.mTreshold;
> > >
> > >   }
> > >
> > >   public void setTreshold(double treshold)
> > >
> > >   {
> > >
> > >     this.mTreshold = treshold;
> > >
> > >   }
> > >
> > >
> > >
> > > This is working fine if I enter valid doubles.
> > >
> > > The following message is displayed if I enter nothing in the input
> > field:
> > >
> > >
> > >
> > > Exception setting property Threshold: of base with class
> > > com.recommind.litigation.client.web.model.Category, Bean:
> > > com.recommind.litigation.client.web.model.Category,
> > > property: Threshold:, newValue: null ,newValue class: null method
> > parameter
> > > class: double, null
> > >
> > >
> > >
> > > The getAsObject method of the NumberConverter returns null as
> > expected.
> > >
> > >
> > >
> > > What should I do now with the treshold property of the Category
> class
> > ?
> > >
> > > I tried without success:
> > >
> > > - setTreshold(Double treshold)
> > >
> > > - setTreshold(Number treshold)
> > >
> > >
> > >
> > > A workaround is to set the value to 0 via javascript but this is not
> a
> > good
> > > alternative.
> > >
> > >
> > >
> > > Michael
> >
> >
>
>
>


-- 
Matthias Wessendorf

further stuff:
blog: http://matthiaswessendorf.wordpress.com/
mail: matzew-at-apache-dot-org

Reply via email to