1

I'm trying to add localisation to my web app which is built with Spring WebFlow and facelets. I want to add support for english and french. I've created my two messages_fr.properties and messages_en.properties files.

My template which I use for all my jsf pages has the following code to define the messages bundle and two links to switch between french and english.

<f:loadBundle basename="messages" var="msg" />
...
<h:commandLink id="changeLocaleFr" action="changeLocale"
class="flag fr">
    <f:param name="ln" value="fr" />
</h:commandLink>
<h:commandLink id="changeLocaleEn" action="changeLocale"
class="flag en">
    <f:param name="ln" value="en" />
</h:commandLink>

I've set up a session local resolver

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />

and a local change interceptor

<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <property name="paramName" value="ln" />
</bean>

which I added to my flow handler mapping

<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    <property name="flowRegistry" ref="flowRegistry" />
    <property name="interceptors">
        <list>
            <ref bean="localeChangeInterceptor"></ref>
        </list>
    </property>
    <property name="order" value="0" />
</bean>

In my flow I have a global transition for changeLocale

<global-transitions>
    <transition on="changeLocale" />
</global-transitions>

All this is almost working. When I click on one of the links, the locale is changed. But I don't see the changes immediatly, I have to manually refresh or navigate to another view to rerender the page with the new langage being used. How can I make the changes appear immediatly after clicking on the link ?

jonasr
  • 1,876
  • 16
  • 18
  • Im so sorry but I've no other way to contact you and its an emergency. I have a question on gwt, could you please help me out. The question is [here][1] [1]: http://stackoverflow.com/questions/20509894/want-to-implement-mark-as-read-feature-in-gwt-cell-list – nanospeck Dec 13 '13 at 05:25

1 Answers1

1

My guess would be that this has something to do with the JSF view root not having changed at all when processing the changeLocale action. Try to add some code like this when processing the locale change:

FacesContext context = FacesContext.getCurrentInstance();
context.setViewRoot(context.getApplication().getViewHandler().createView(context, context.getViewRoot().getViewId()));

That way JSF is forced to refresh the state of all components.

klr8
  • 655
  • 1
  • 6
  • 12