Key point is that you need to set the locale by UIViewRoot#setLocale()
before the view is ever rendered. The <f:view locale="#{languageBean.currentLocale}">
is only set during building of the view. So any request based actions which are invoked thereafter with the intent to change only the bean property won't have any effect. You really need to manually invoke UIViewRoot#setLocale()
as well.
Easiest would be to perform that UIViewRoot#setLocale()
job in the setter of the currentLocale
property as well. The bean example as mentioned in the answer of the link provided by Daniel in your question comment does exactly that: JSF 2.0 set locale throughout session from browser and programmatically. This way no ugly JS hack is necessary to reload the page once.
Based on your own answer, there's another possible problem: your "receiver bean" seems to be request scoped and not be the #{languageBean}
itself. If this bean is constructed for the first time after any locale/language related aspects of the view (e.g. language dropdown, localized text, etc), then it's too late to change them as well. You would like to move the construction of the bean to the pre render view event (e.g., via <f:event listener>
). An alternative is to just perform the request parameter collecting job in the getter of the currentLocale
property instead.