faces-config.xml
:
ru
One small remark to @BalusC great solution. If we have
which executes some method in backing bean. Locale available from call to FacesContext.getCurrentInstance().getViewRoot().getLocale()
inside that method would be locale that is set by user browser or default application locale, not that locale that is set on session bean by user selection(of course they can match if browser locale equals that locale that user selected).
I can stand corrected, because maybe I did something wrong when implementing solution provided by @BalusC.
EDIT. After playing with JSF lifecycle, this behavior with locale is not related to
, because there is similar behavior also with @PostContruct
.
in request(after user selected locale) is executed in render response phase.
and @PostContruct
methods are executed in invoke application phase. That is why logic that is executed in this method do not have access to user selected locale.
Solution that we using when we need correct locale is to inject(CDI) localeBean
in other backing bean that contains
and @PostContruct
methods, and then set locale with UIViewRoot#setLocale()
from localeBean
in beginning of these methods.