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.

4

1 回答 1

0

JSF 调用具有默认语言环境的 Integer.toString() 或 Long.toString() 方法。

第一个解决方案:

Locale.setDefault(myHardcodeLocale);从您的ServletContextListener调用

第二种解决方案

创建自定义格式化程序。您可以使用 facelets 并为数字创建自己的 outputText。

<h:outputText value="#{myController.myNumberValue}">
    <f:convertNumber type="#,###.00"/>
</h:outputText>
于 2013-04-08T10:37:10.373 回答