开发者

How do I display the message in a different locale

We have a requirement to show a certain page alone in a different locale. (e.g in a certain page if the topic of discussion is related to English then we pick up the messages from the messages_en.properties, but if the topic of discussion is in French or German we need to show the messages in the appropriate language.

How to change the following bean invocation to take in the locale as a parameter in the xhtml page #{messages['label.hello']}.

The abov开发者_如何学JAVAe defaults to the english locale, how do I pass the locale dynamically?


On the server side, just do it

private @In LocaleSelector localeSelector;

And set up as follows

localeSelector.setLanguage("en");
localeSelector.setCountry("US");


I want to note that JSF also reads the preferred language in your browser, and displays that if that language is supported by your application.

So really if you support lots of languages, then you don't need to define server side locale.

In faces-config.xml

 <application>
  <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
  <locale-config>
     <default-locale>en</default-locale>
     <supported-locale>se</supported-locale>
     <supported-locale>dk</supported-locale>
     <supported-locale>no</supported-locale>
     <supported-locale>it</supported-locale>
     <!-- etc -->
  </locale-config>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜