2010-10-28 51 views
1

我試圖將本地化添加到使用Spring WebFlow和facelets構建的我的web應用程序中。我想添加對英語和法語的支持。我創建了兩個messages_fr.properties和messages_en.properties文件。使用Spring WebFlow轉換刷新視圖

我用於我的所有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> 

在我的流程中,我有一個全球性的tra無法更改地區

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

所有這一切幾乎都有效。當我點擊其中一個鏈接時,語言環境發生了變化。但我沒有立即看到這些更改,我必須手動刷新或導航到另一個視圖,以便使用新的語言重新渲染頁面。點擊鏈接後,如何立即顯示更改?

+0

我很抱歉,但我沒有其他辦法與您聯繫,並且發生緊急情況。我有一個關於gwt的問題,請你幫我解決。問題是[這裏] [1] [1]:http://stackoverflow.com/questions/20509894/want-to-implement-mark-as-read-feature-in-gwt-cell-list – nanospeck 2013-12-13 05:25:34

回答

1

我的猜測是,這與JSF視圖根在處理changeLocale動作時根本沒有改變有關。 嘗試處理的語言環境變化時添加一些像這樣的代碼:

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

JSF這樣被強制刷新所有組件的狀態。