aspose file tools
The moose likes JSF and the fly likes Problem using convertNumber for decimal numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Problem using convertNumber for decimal numbers" Watch "Problem using convertNumber for decimal numbers" New topic
Author

Problem using convertNumber for decimal numbers

camilla bat
Greenhorn

Joined: Jul 29, 2005
Posts: 14
I'm using a f:convertNumber on an inputText. I want the number that is typed to convert to a Double (or double). This is my inputText:

<f:inputText value="#{myBean.length}" >
<f:convertNumber pattern="####0.0"/>
</af:inputText>

The format of the input is supposed to be maximal 5 digits, and one decimal. If the user types e.g. 4, I want the converter to convert this to a Double 4.0. But it takes it as a Long, so I get a classCastException.

Is it possible at all to use this converter for my purpose: convert to a one decimal number. The pattern is maybe wrong?
Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
i never tried pattern but i think this will server your purpose

<f:convertNumber maxFractionDigits="1" minFractionDigits="1" maxIntegerDigits="5" groupingUsed="false"/>

I hope you have defined 'length' as double in your managedbean.

Thanks,
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Problem using convertNumber for decimal numbers
 
Similar Threads
NumberConverter
convertNumber question
Apply immediately a conveter to inputText
How do I NOT require currency symbol on input, but still display it with convertNumber?
f:convertnumber qustion?