2011-04-11 66 views
1

我在採用以下方式配置兩個流:關於產品解決方案

<?xml version="1.0" encoding="UTF-8"?> 

<flow xmlns="http://www.springframework.org/schema/webflow" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/webflow 
     http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"> 
    <on-start> 
     <evaluate expression="mytService.createUserForm()" result="flowScope.userForm" /> 
    </on-start> 

    <view-state id="register" view="account/registerForm" model="userForm">  
     <on-render> 
      <set name="requestScope.countryList" value="mytService.getCountryList()" /> 
     </on-render> 
     <transition on="submitRegistration" to="addAccount" bind="true" validate="true" /> 
     <transition on="cancelRegistration" to="cancelRegistration" 
      bind="false" /> 
    </view-state> 

    <view-state id="accountAdded" view="account/registeringForm"> 
     <transition on="sendOnceAgain" to="registering"> 
      <evaluate expression="myService.sendOnceAgain()"></evaluate> 
     </transition> 
    </view-state> 

    <action-state id="addAccount"> 
     <evaluate expression="myService.addAccount(userForm)" /> 
     <transition to="accountAdded" /> 
    </action-state> 

    <end-state id="cancelRegistration" view="externalRedirect:contextRelative:/home.do" /> 

    <global-transitions> 
     <transition on="changeLang"> 

     </transition> 
    </global-transitions> 
</flow> 

和:

<?xml version="1.0" encoding="UTF-8"?> 
<flow xmlns="http://www.springframework.org/schema/webflow" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/webflow 
     http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"> 

    <input name="hash" required="true"/> 

    <on-start> 
     <evaluate expression="myService.createUserForm()" result="flowScope.userForm" /> 
    </on-start> 

    <action-state id="decideAction"> 
     <set name="flowScope.goTo" value ="mytService.verifyHash(hash)" /> 
     <transition to="${goTo}"></transition> 
    </action-state> 

    <view-state id="correctVerify" view="account/registeredForm" model="userForm"> 
     <transition on="addPhoneNumber" to="correctVerify"> 
      <evaluate expression="myService.addPhoneNumber(userForm)" /> 
     </transition> 
     <transition on="deletePhoneNumber" to="correctVerify"> 
      <evaluate expression="myService.deletePhoneNumber(userForm, requestParameters.deleteNumber)" /> 
     </transition> 
    </view-state> 

    <view-state id="notCorrectVerify" view="account/registerForm"> 

    </view-state> 

    <view-state id="start"> 
    </view-state> 


    <global-transitions> 
     <transition on="changeLang">  
     </transition> 
    </global-transitions> 
</flow> 

我也有改變語言組合。我的問題是如何實現語言的變化?如何改變語言?

<div id="header"> 
    <div id="left"> 
     <div id="logo"></div> 
    </div> 
    <div id="right"> 
     <ul> 
      <li class="helpLink"><a href="#">Pomoc</a></li> 
      <li class="langSelect"> 
      <form id="langForm" action="${flowExecutionUrl}&_eventId=changeLang" method="post"> 
       <input type="hidden" value="${execution}" name="execution" /> 
       <select name="lang" id="lang" class="styled" onchange="this.form.submit()"> 
        <option value="pl" ${sessionScope.lang == 'pl' ? 'selected' : ''} >PL</option> 
        <option value="en" ${sessionScope.lang == 'en' ? 'selected' : ''} >EN</option> 
       </select> 
      </form> 
      </li> 
     </ul> 
    </div> 
</div> 

配置:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" 
    xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:flow="http://www.springframework.org/schema/webflow-config" 
    xmlns:webflow="http://www.springframework.org/schema/webflow-config" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd 
     http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
     http://www.springframework.org/schema/webflow-config 
     http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd"> 

    <context:annotation-config /> 

    <context:component-scan base-package="pl" /> 

    <bean id="myService" class="pl.service.MyService" /> 

    <bean 
     class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> 

    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
     <property name="mappings"> 
      <value> 
       /account/register.do=flowController 
       /account/verify.do=flowController  
      </value> 
     </property> 
     <property name="alwaysUseFullPath" value="true" /> 
    </bean> 

    <bean 
     class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> 

    <bean 
     class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /> 

    <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/WEB-INF/jsp/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 


    <bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController"> 
     <property name="flowExecutor" ref="flowExecutor" /> 
    </bean> 

    <webflow:flow-executor id="flowExecutor" 
     flow-registry="flowRegistry"></webflow:flow-executor> 

    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"> 
     <property name="flowExecutor" ref="flowExecutor" /> 
    </bean> 

    <webflow:flow-registry id="flowRegistry" 
     flow-builder-services="flowBuilderServices"> 
     <webflow:flow-location id="verify" path="/WEB-INF/flows/verify.xml"></webflow:flow-location> 
     <webflow:flow-location id="register" path="/WEB-INF/flows/register.xml"></webflow:flow-location> 
    </webflow:flow-registry> 

    <webflow:flow-builder-services id="flowBuilderServices" 
     view-factory-creator="viewFactoryCreator" /> 

    <bean id="viewFactoryCreator" 
     class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator"> 
     <property name="viewResolvers"> 
      <list> 
       <ref bean="viewResolver" /> 
      </list> 
     </property> 
    </bean> 

    <!-- Application Message Bundle --> 

    <bean id="messageSource" 
     class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
     <property name="basename" value="/WEB-INF/messages/messages" /> 
     <property name="defaultEncoding" value="UTF-8" /> 
    </bean> 

    <bean id="localeResolver" 
     class="org.springframework.web.servlet.i18n.CookieLocaleResolver"> 
     <property name="defaultLocale" value="pl" /> 
    </bean> 

    <mvc:interceptors> 
     <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
      <property name="paramName" value="lang" /> 
     </bean> 
    </mvc:interceptors> 

</beans> 

回答

0

LocaleChangeIntercepter會做的伎倆。

您已經配置了它。

要了解更多詳情,請參閱Spring Reference章節15.6 Using locales

如果你想看到它的行動,建立一個小的春季roo應用程序,並添加第二種語言。然後你可以瀏覽源代碼添加看看他們(Roo)是如何做到的。

+0

謝謝。 Roo很棒。 – user6778654 2011-04-13 08:03:25