У меня два потока настроены следующим образом:
<?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>
LocaleChangeIntercepter сделает свое дело.
Вы уже настроили его.
Чтобы узнать больше, взгляните на справочную главу Spring 15.6 Использование локалей .
Если вы хотите увидеть его в действии, создайте небольшое приложение Spring roo и добавьте второй язык. Затем вы можете просмотреть исходный код и посмотреть, как они (Ру) сделали это.
Я бы сказал, что веб-поток Spring не является правильным способом обработки специфичных для локали представлений. Ознакомьтесь с обработчиками вида и I18N:
http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html