0

Depending on the operating system $LANG value, the display of a number is different in a JSF page. For example, with the code :

<h:outputText value="#{myController.myNumberValue}" />

With the $LANG = en_US.ISO-8859-1, I have "623, 451". With the $LANG = fr_FR.UTF-8, I have "623 451".

My question is how my application can be independent from the operation system configuration?

I tried the following configuration in faces-config.xml but it doesn't work :

<locale-config>
    <default-locale>en</default-locale>
</locale-config>

I also tried to encapsulate h:outputText tag within the following tag, but it doesn't work too :

<f:view locale="en">
    <h:outputText value="#{myController.myNumberValue}" />    
</f:view>

Any idea to resolve my problem?

Thanks in advance.

jsebfranck
  • 704
  • 2
  • 9
  • 18

1 Answers1

0

JSF call for you method Integer.toString() or Long.toString() with default locale.

First solution:

Call Locale.setDefault(myHardcodeLocale); from your ServletContextListener

Second solution:

Create custom formatter. You can use facelets and create your own outputText for numbers.

<h:outputText value="#{myController.myNumberValue}">
    <f:convertNumber type="#,###.00"/>
</h:outputText>
Andrzej Jozwik
  • 14,331
  • 3
  • 59
  • 68
  • This is not exactly true. JSF uses `` which indeed defaults to `Locale#getDefault()` when not specified. However, the OP has it specified. So this problem is totally unexpected as the code provided so far should work. So, either OP is using some JSF impl/version exposing a bug, or OP isn't running the code it think it is running, or the OP actually didn't show an SSCCE. – BalusC Apr 08 '13 at 11:45
  • OK, but second solution is OP independent. In my experience when you start jvm you should override default locale, timezone. You never know, what will be defined on production. See [how do I set the default locale for my JVM?](http://stackoverflow.com/a/8809137) – Andrzej Jozwik Apr 08 '13 at 12:00