-
1. Re: Injected locale not the same as getLocale()?
kenfinni Mar 13, 2012 11:05 AM (in response to membersound)Are you using Seam 3 Faces as well? As by default the Seam 3 International module doesn't integrate with JSF, Seam 3 Faces provides that.
Regards
Ken
-
2. Re: Injected locale not the same as getLocale()?
membersound Mar 13, 2012 11:56 AM (in response to kenfinni)yes I have both seam-faces and seam-international in my pom.
-
3. Re: Injected locale not the same as getLocale()?
kenfinni Mar 13, 2012 3:13 PM (in response to membersound)When you update the locale in the view, is it done like this: https://github.com/seam/examples/blob/master/timeanddate/src/main/java/org/jboss/seam/international/examples/timeanddate/locale/LocaleBean.java?
If not, it may be that Faces has the new Locale, but not Seam 3 i18n.
Ken
-
4. Re: Injected locale not the same as getLocale()?
membersound Mar 13, 2012 6:22 PM (in response to kenfinni)Hmm no, I made it as I described above with
facesContext.getViewRoot().setLocale(locale);
Adapted my class with the stuff from your example, including converter and so on, and: it works
tyvm!
Only one thing remaining:
I have to execute both of these events to get my i18n work properly:
@Inject FacesContext facesContext; public void setUserLocale(Locale locale) { facesContext.getViewRoot().setLocale(locale); localeEvent.fire(locale); }
If I ommit the fire event, I do not get the messages.properties resolved.
If I ommit the explicit setLocale statement, I do not get my textbundle resolved.
Do you have a clue why this behaves that strange?
The
Messages messages;
are created with BundleKey, which gets the bundle name from
facesContext.getApplication().getMessageBundle();
I use the messages from within my backing beans to display error messages.
The textbundle ist just used in jsf via el-expression.
Both are defined in faces-config.xml as follows:
<message-bundle>messages</message-bundle> <resource-bundle> <base-name>textbundle</base-name> <var>textbundle</var> </resource-bundle>
-
5. Re: Injected locale not the same as getLocale()?
membersound Mar 13, 2012 6:44 PM (in response to membersound)Oh no I just discovered that when using implicit navigation in JSF the locale settings get lost too.
-
6. Re: Injected locale not the same as getLocale()?
kenfinni Mar 14, 2012 11:28 AM (in response to membersound)You should be able to use i18n Messages class as well, instead of ResourceBundle with FacesContext Locale for retrieving messages.
Did you take a look at the https://github.com/seam/examples/tree/master/timeanddate example?
Some of the items that would be of interest are:
- Definition of resource properties in faces-config.xml (don't think you need messages and textbundle defined)
- Use of locale on f:view here: https://github.com/seam/examples/blob/master/timeanddate/src/main/webapp/template.xhtml (this may solve issue of Faces losing locale and prevent you from having to set it directly)
- Use of injected Messages class here: https://github.com/seam/examples/blob/master/timeanddate/src/main/java/org/jboss/seam/international/examples/timeanddate/locale/LocaleBean.java
Hope that helps
Ken
-
7. Re: Injected locale not the same as getLocale()?
membersound Mar 14, 2012 11:50 AM (in response to kenfinni)Yes I rewrote my localeBean based on this example.
Ty for the f:view hint. Did not know about this and it solved my problem of persisting the locale change.
Anyhow I still have to execute both the fire event and the facesContext...setLocale to make all my i18n work.
Which is strange, but to be honest, a minor problem.