Code: Select all
<f:view contentType="text/html" locale="#{sessionBean.locale}">
...........
<h:outputText value="#{sessionBean.language}"/>
<h:selectOneMenu id="language_select" value="#{sessionBean.language}">
<f:selectItem itemLabel="English" itemValue="en"/>
<f:selectItem itemLabel="Français" itemValue="fr"/>
<p:ajax process="language_select" update="sidebar1 post_block footer" event="change"/>
</h:selectOneMenu>
Code: Select all
public Locale getLocale() {
if (locale==null) {
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext ec=context.getExternalContext();
locale=ec.getRequestLocale();
if (locale==null) locale=Locale.ENGLISH;
}
return locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
}
public String getLanguage() {
return getLocale().getLanguage();
}
public void setLanguage(String language) {
setLocale(new Locale(language));
}
I tried to force locale "FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);" - doesn't work. I probably have to somehow reload bundles or something?