Changing language without changing locale in JSF

I currently have a JSF application which sets the locale based on a user's choice of language. He gets a dropdown, and when choosing English, I set the locale to en, etc. This works very nice with number formats as well as with the language strings loaded from my ResourceBundle.

So for en, I get English words and a . as decimal seperator. For fr, I get French and a , as decimal seperator.

However, there is now a requirement that for this website, the number format must always have a , as decimal seperator. So, I was thinking to keep the locale fixed to fr.

Still the user must be able to change his language. So, is it possible in JSF to load a different language without changing the locale?


Seams you need a special solution for formatting, so overwriting the formatters might be the better solution. I think JSF supports replacing the default number format.


Just explicitly specify the locale attribute of the <f:convertNumber> tags which you're using there.

Eg

<f:convertNumber ... locale="fr" />

or something like

<f:convertNumber ... locale="#{app.defaultNumberLocale}" />

It would otherwise indeed default to UIViewRoot#getLocale() , as you're experiencing.

See also:

  • <f:convertNumber> tag documentation - read the locale attribute
  • 链接地址: http://www.djcxy.com/p/67354.html

    上一篇: 在iOS中查找货币的小数位数

    下一篇: 在不改变JSF语言环境的情况下更改语言