You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Yannick Le Teigner <ya...@laposte.net> on 2005/11/08 03:06:56 UTC

convertNumber returned type?

Hello,

I use f:convertNumber in my application to display localized number value.
Problam is that if the number entered in the input box by the user has 
any decimal digits (i.e. 14.75) then the returned number is a Double. If 
the number does not have any decimal digit (i.e 103), then the returned 
number is a Long.
The only solution I have found is to put MyBean.value as an object of 
type Object, but I have to do type cast all over the place...

<h:inputText value="#{MyBean.value}">
  <f:convertNumber type="number" maxFractionDigits="2"/>
</h:inputText>

Has anyone found a way to force the type of the returned value?

Thanks,
Yannick

Re: convertNumber returned type?

Posted by Yannick Le Teigner <ya...@laposte.net>.
Mike,

Thanks for pointing that out, using java.lang.Number works as expected.



Mike Kienenberger wrote:

>It's supposed to work as you'e described.  As Dave says below, use
>"java.lang.Number" as your data type, and it'll work for both a Long
>and a Double.   You can then use Number.doubleValue() no matter which
>underlying type was returned.
>
>http://java.sun.com/j2ee/javaserverfaces/1.1/docs/api/javax/faces/convert/NumberConverter.html
>
>"The getAsObject() method parses a String into an java.lang.Double or
>java.lang.Long...."
>
>On 11/7/05, Yannick Le Teigner <ya...@laposte.net> wrote:
>  
>
>>Hello,
>>
>>I use f:convertNumber in my application to display localized number value.
>>Problam is that if the number entered in the input box by the user has
>>any decimal digits (i.e. 14.75) then the returned number is a Double. If
>>the number does not have any decimal digit (i.e 103), then the returned
>>number is a Long.
>>The only solution I have found is to put MyBean.value as an object of
>>type Object, but I have to do type cast all over the place...
>>
>><h:inputText value="#{MyBean.value}">
>>  <f:convertNumber type="number" maxFractionDigits="2"/>
>></h:inputText>
>>
>>Has anyone found a way to force the type of the returned value?
>>
>>Thanks,
>>Yannick
>>
>>    
>>
>
>  
>

Re: convertNumber returned type?

Posted by Mike Kienenberger <mk...@gmail.com>.
It's supposed to work as you'e described.  As Dave says below, use
"java.lang.Number" as your data type, and it'll work for both a Long
and a Double.   You can then use Number.doubleValue() no matter which
underlying type was returned.

http://java.sun.com/j2ee/javaserverfaces/1.1/docs/api/javax/faces/convert/NumberConverter.html

"The getAsObject() method parses a String into an java.lang.Double or
java.lang.Long...."

On 11/7/05, Yannick Le Teigner <ya...@laposte.net> wrote:
> Hello,
>
> I use f:convertNumber in my application to display localized number value.
> Problam is that if the number entered in the input box by the user has
> any decimal digits (i.e. 14.75) then the returned number is a Double. If
> the number does not have any decimal digit (i.e 103), then the returned
> number is a Long.
> The only solution I have found is to put MyBean.value as an object of
> type Object, but I have to do type cast all over the place...
>
> <h:inputText value="#{MyBean.value}">
>   <f:convertNumber type="number" maxFractionDigits="2"/>
> </h:inputText>
>
> Has anyone found a way to force the type of the returned value?
>
> Thanks,
> Yannick
>

Re: convertNumber returned type?

Posted by Yannick Le Teigner <ya...@laposte.net>.
I tried with my-faces-1.1.1 and the daily build from 11/07 and both of 
them don't work.
They return Double or Long depending on the entered number.


If the backing bean object (amountWithVat) is of type Double:
Enter 4,784 or 598 =>

17188 [TP-Processor7] ERROR 
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/montecristo]  
- Cannot set value for expression '#{OrderCreation.amountWithVat}' to a 
new value of type java.lang.Long
javax.faces.el.EvaluationException: Cannot set value for expression 
'#{OrderCreation.amountWithVat}' to a new value of type java.lang.Long
        at 
org.apache.myfaces.el.ValueBindingImpl.setValue(ValueBindingImpl.java:304)
        at javax.faces.component.UIInput.updateModel(UIInput.java:226)
        at javax.faces.component.UIInput.processUpdates(UIInput.java:165)
        at 
javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:428)

enter 478.4 => Ok

enter 4,789.39=> Ok


If the backing bean object is of type Long:

enter 4,784 or 598 => Ok

enter 478.4 or 4,789.39 =>
44306 [TP-Processor5] ERROR 
org.apache.catalina.core.ContainerBase.[Catalina].[l
ocalhost].[/montecristo]  - Cannot set value for expression 
'#{OrderCreation.amo
untWithVat}' to a new value of type java.lang.Double
javax.faces.el.EvaluationException: Cannot set value for expression 
'#{OrderCrea
tion.amountWithVat}' to a new value of type java.lang.Double
        at 
org.apache.myfaces.el.ValueBindingImpl.setValue(ValueBindingImpl.java
:304)
        at javax.faces.component.UIInput.updateModel(UIInput.java:226)
        at javax.faces.component.UIInput.processUpdates(UIInput.java:165)
        at 
javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.
java:428)





Dave wrote:

> JSF should use BigDecimal. One type for all different numbers.
>
> */Yannick Le Teigner <ya...@laposte.net>/* wrote:
>
>     Hello,
>
>     I use f:convertNumber in my application to display localized
>     number value.
>     Problam is that if the number entered in the input box by the user
>     has
>     any decimal digits (i.e. 14.75) then the returned number is a
>     Double. If
>     the number does not have any decimal digit (i.e 103), then the
>     returned
>     number is a Long.
>     The only solution I have found is to put MyBean.value as an object of
>     type Object, but I have to do type cast all over the place...
>
>
>
>
>
>     Has anyone found a way to force the type of the returned value?
>
>     Thanks,
>     Yannick
>
> ------------------------------------------------------------------------
> Yahoo! FareChase - Search multiple travel sites in one click. 
> <http://us.lrd.yahoo.com/_ylc=X3oDMTFqODRtdXQ4BF9TAzMyOTc1MDIEX3MDOTY2ODgxNjkEcG9zAzEEc2VjA21haWwtZm9vdGVyBHNsawNmYw--/SIG=110oav78o/**http%3a//farechase.yahoo.com/> 



Re: convertNumber returned type?

Posted by Dave <ja...@yahoo.com>.
I tried Number type, it worked in terms of type. However,
 
<f:convertNumber type="currency" currencySymbol="$"/>
 
If I specify currencSymbol, displaying as outputText is OK: $98.50. I like it.
but for editing using <inputTex>, no matter what I type, I got  Conversion Error : Specified value is not a valid number. I tried:  $56, $98.5, $86.56, 56, 98.5, 86.56.

 

If I remove the currencySymbol, it works fine. but a weird currency symbol show up like:

 ยกรจ86.56 

what is wrong? Anyone using <convertNumber> for currency successfully?
 
Thanks.
Dave

Dave <ja...@yahoo.com> wrote:
JSF should use BigDecimal. One type for all different numbers.

Yannick Le Teigner <ya...@laposte.net> wrote: Hello,

I use f:convertNumber in my application to display localized number value.
Problam is that if the number entered in the input box by the user has 
any decimal digits (i.e. 14.75) then the returned number is a Double. If 
the number does not have any decimal digit (i.e 103), then the returned 
number is a Long.
The only solution I have found is to put MyBean.value as an object of 
type Object, but I have to do type cast all over the place...





Has anyone found a way to force the type of the returned value?

Thanks,
Yannick



---------------------------------
Yahoo! FareChase - Search multiple travel sites in one click. 
		
---------------------------------
 Yahoo! FareChase - Search multiple travel sites in one click.  

Re: convertNumber returned type?

Posted by Dave <ja...@yahoo.com>.
JSF should use BigDecimal. One type for all different numbers.

Yannick Le Teigner <ya...@laposte.net> wrote:Hello,

I use f:convertNumber in my application to display localized number value.
Problam is that if the number entered in the input box by the user has 
any decimal digits (i.e. 14.75) then the returned number is a Double. If 
the number does not have any decimal digit (i.e 103), then the returned 
number is a Long.
The only solution I have found is to put MyBean.value as an object of 
type Object, but I have to do type cast all over the place...





Has anyone found a way to force the type of the returned value?

Thanks,
Yannick


		
---------------------------------
 Yahoo! FareChase - Search multiple travel sites in one click.