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
>
>

Reply via email to