aspose file tools*
The moose likes JSF and the fly likes How do I NOT require currency symbol on input, but still display it with convertNumber? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How do I NOT require currency symbol on input, but still display it with convertNumber?" Watch "How do I NOT require currency symbol on input, but still display it with convertNumber?" New topic
Author

How do I NOT require currency symbol on input, but still display it with convertNumber?

Justin Olomar
Greenhorn

Joined: Sep 08, 2009
Posts: 10
We currently have a field that displays currency. The method we're using to display our BigDecimal as currency is:
This works great, excpet that this requires the user to enter the dollar sign. If they don't, Faces gives a '1.33' could not be understood as a currency value. Example: $99.99 type of error. What is the accepted way to display the currency symbol in the input box, but not REQUIRE it if the user wants to change the value?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16054
    
  21

That's extremely odd. According to Sun's official documentation, the currency code and symbol are "applied only when formatting currencies." (emphasis mine).

Are you supplying a currencyCode attribute on your formatNumber tag?


Customer surveys are for companies who didn't pay proper attention to begin with.
cum grano salis
Greenhorn

Joined: Jan 15, 2010
Posts: 2
Justin Olomar wrote:We currently have a field that displays currency. The method we're using to display our BigDecimal as currency is:
This works great, excpet that this requires the user to enter the dollar sign. If they don't, Faces gives a '1.33' could not be understood as a currency value. Example: $99.99 type of error. What is the accepted way to display the currency symbol in the input box, but not REQUIRE it if the user wants to change the value?
It's not possible with the reference implementation and apparently won't be possible until somewhere in JSF 2. Here's the enhancement and a couple ways to work around it:

Have f:convertNumber add currency symbol if not present for type=currency

They Should Have Called Java “Molasses”
Justin Olomar
Greenhorn

Joined: Sep 08, 2009
Posts: 10
cum grano salis wrote:
Justin Olomar wrote:We currently have a field that displays currency. The method we're using to display our BigDecimal as currency is:
This works great, excpet that this requires the user to enter the dollar sign. If they don't, Faces gives a '1.33' could not be understood as a currency value. Example: $99.99 type of error. What is the accepted way to display the currency symbol in the input box, but not REQUIRE it if the user wants to change the value?
It's not possible with the reference implementation and apparently won't be possible until somewhere in JSF 2. Here's the enhancement and a couple ways to work around it:

Have f:convertNumber add currency symbol if not present for type=currency

They Should Have Called Java “Molasses”
Thank you very much! I've written a class that extends NumberConverter just as shown in the non-AspectJ example you linked to. How do I get my custom converter registered with all fields using the <f:convertNumber type="currency" /> converter? I've tried adding the following to my faces-config.xml, but unfortunately it still seems to use the built-in NumberConverter class.
Sorry for the newbie questions, but, well....I AM a newbie to JSF.
cum grano salis
Greenhorn

Joined: Jan 15, 2010
Posts: 2
Justin Olomar wrote:Thank you very much! I've written a class that extends NumberConverter just as shown in the non-AspectJ example you linked to. How do I get my custom converter registered with all fields using the <f:convertNumber type="currency" /> converter? I've tried adding the following to my faces-config.xml, but unfortunately it still seems to use the built-in NumberConverter class.
Sorry for the newbie questions, but, well....I AM a newbie to JSF. :banghead:

If you are using a tag (f:convertNumber), it will still use the code backing that tag. The converters registered per class, as you have configured, should automatically be used when it cannot find another converter and you haven't specified one. Did you try removing the f:convertNumber tag, not specifying an f:converter, or a converter on your h:inputText, h:outputText, or whatever tag you're using, and seeing if it works? You will almost certainly run into an issue because you then have no way of specifying the type of conversion (you probably want "currency", since that's the topic). If you hard code it to use currency, it will affect every Number conversion, and that's probably not what you want.

Since you still want to use f:convertNumber, you have to reconfigure the f tag library somehow. You can patch it. You can also create your own tag library with your own convertNumber tag. Or, you can just amend what's already there with the AspectJ example.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I NOT require currency symbol on input, but still display it with convertNumber?