我有两个以下列方式配置的流程:
<?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 :(得分:0)
我想说Spring Web流不是处理特定于语言环境的视图的正确方法。查看视图处理程序和I18N:
http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html
答案 1 :(得分:0)
LocaleChangeIntercepter可以解决问题。
您已经配置了它。
要阅读更多详细信息,请查看Spring参考章节15.6 Using locales。
如果您想看到它的实际效果,请构建一个小型的Spring roo应用程序,并添加第二种语言。然后你可以浏览源代码添加,看看他们(Roo)是如何做到的。