使用 Spring WebFlow 转换刷新视图
我正在尝试将本地化添加到我的网络应用程序中,该应用程序是使用 Spring WebFlow 和 Facelets 构建的。我想添加对英语和法语的支持。我创建了两个 messages_fr.properties 和 messages_en.properties 文件。
我用于所有 jsf 页面的模板具有以下代码来定义消息包和两个用于在法语和英语之间切换的链接。
<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>
我已经设置了一个会话本地解析器
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />
和一个本地更改拦截器
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="ln" />
</bean>
,我将其添加到我的流程处理程序映射
<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>
中。在我的流程中,我有一个针对changeLocale 的全局转换,
<global-transitions>
<transition on="changeLocale" />
</global-transitions>
所有这些都几乎可以正常工作。当我单击其中一个链接时,区域设置就会更改。但我没有立即看到更改,我必须手动刷新或导航到另一个视图才能使用正在使用的新语言重新呈现页面。如何使更改在单击链接后立即显示?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是,这与处理changeLocale 操作时JSF 视图根根本没有改变有关。
尝试在处理区域设置更改时添加一些类似这样的代码:
这样 JSF 就会强制刷新所有组件的状态。
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:
That way JSF is forced to refresh the state of all components.