JSF internationalization from the moment the page loads.?
I want to implement internationalization in JSF, most of the techniques given on net involves asking a user his/her locale and setting the value in a session bean. But i want the locale to be set based on the request accept-language header and JSF should have some filter in place which sets the locale开发者_运维技巧 prior to the loading of the first page and then sets it in the language session beans which i can reuse like .
Thus is there some Locale filter like functionality implemented with jsf which can be used to set the Locale?
Thanks!
The locale should be detected automatically by a Java EE application if you have configured it correctly in your faces-config.xml and have the correct resource bundle files. This tutorial from Netbeans gives a good introduction.
Additionally, a web application can detect the client's locale based on the request as by this quote from the Java EE tutorial:
To get the correct strings for a given user, a web application either retrieves the locale (set by a browser language preference) from the request using the getLocale method, or allows the user to explicitly select the locale.
There is also an example how to use the getLocale method:
FacesContext ctx = FacesContext.getCurrentInstance();
Locale locale = ctx.getViewRoot().getLocale();
You can put it in session state to have easy access.
精彩评论