webtier@glassfish.java.net

Changing Locale Dynamically

From: <webtier_at_javadesktop.org>
Date: Sat, 29 May 2010 15:19:47 PDT

I am confused about how you are supposed to go about changing the Locale. I am doing this:

&lt;f:view locale="#{person.locale}"&gt;
&lt;f:loadBundle basename="messages" var="msgs"/&gt;

&lt;h:form>
&lt;h:commandButton value="#{msgs.switchLanguage}"
                 actionListener="#{person.swapLocale}"
                 immediate="true"/&gt;
&lt;/h:form&gt;

&lt;/f:view&gt;

The swapLocale method swaps the Locale to/from English and Spanish, and my Person bean is session-scoped. The problem is that when I press the button, I don't get the new Locale until I manually reload the page. I put a trace in the swapLocale and getLocale methods, and I find that when I press the button, the getLocale method is called, then the swapLocale method is called, and the getLocale method is [b]not [/b]called again after the call to swapLocale. I get the same behavior with action instead of actionListener, and also if I remove immediate="true".

Clearly, I am misunderstanding the lifecycle here. Why isn't getLocale being called [i]after [/i]the actionListener method [swapLocale]? What is the proper way to let the user set the Locale?

Thanks!

                - Marty
-----
JSF 2.0 Training Course: http://courses.coreservlets.com/public-courses/jsf2/
[Message sent by forum member 'martyhall']

http://forums.java.net/jive/thread.jspa?messageID=471955