我正在使用Spring MVC 3和Spring Webflow 2.3.2开发Web应用程序。
我希望能够在流页面上添加i18n消息。它在非流页面上正常工作。我可以切换语言,它可以正常工作。
但是当用户进入网络流程时,只会显示默认消息。
我正在使用<spring:message />
代码。
我用Google搜索没有成功。
这是我的app-servlet.xml配置:
<mvc:interceptors>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
</mvc:interceptors>
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="es" />
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="/WEB-INF/i18n/messages" />
<property name="defaultEncoding" value="UTF-8" />
<property name="cacheSeconds" value="60"/>
</bean>
这是我的webflow.xml配置:
<mvc:annotation-driven />
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="order" value="-1" />
<property name="flowRegistry" ref="flowRegistry" />
</bean>
<!-- Dispatches requests mapped to flows to FlowHandler implementations -->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
<property name="flowExecutor" ref="flowExecutor" />
</bean>
<!-- Executes flows: the entry point into the Spring Web Flow system -->
<webflow:flow-executor id="flowExecutor">
<webflow:flow-execution-listeners>
<webflow:listener ref="securityFlowExecutionListener" />
</webflow:flow-execution-listeners>
</webflow:flow-executor>
<!-- The registry of executable flow definitions -->
<webflow:flow-registry id="flowRegistry"
base-path="/WEB-INF/jsp" flow-builder-services="flowBuilderServices" >
<webflow:flow-location-pattern value="/**/*-flow.xml" />
</webflow:flow-registry>
<!-- Plugs in a custom creator for Web Flow views -->
<webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator"
conversion-service="conversionService"
development="true" validator="validator" />
<bean id="conversionService" class="com.zxxztech.zecure.services.webflow.ApplicationConversionService">
<constructor-arg ref="applicationConversionService" />
</bean>
<bean id="applicationConversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean" />
<!-- Configures Web Flow to use Tiles to create views for rendering; Tiles allows for applying consistent layouts to your views -->
<bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
<property name="viewResolvers" ref="tilesViewResolver"/>
<property name="useSpringBeanBinding" value="true" />
</bean>
<!-- Installs a listener to apply Spring Security authorities -->
<bean id="securityFlowExecutionListener" class="org.springframework.webflow.security.SecurityFlowExecutionListener" />
<bean id="tilesViewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="requestContextAttribute" value="requestContext " />
<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" />
<property name="order" value="1" />
<property name="contentType" value="text/html;charset=UTF-8" />
</bean>
<!-- Configures the Tiles layout system -->
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/jsp/**/views.xml</value>
</list>
</property>
</bean>
<!-- Resolves logical view names returned by Controllers to Tiles; a view
name to resolve is treated as the name of a tiles definition -->
<!-- Bootstraps JSR-303 validation and exposes it through Spring's Validator
interface -->
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
这是我的jsp页面的一个片段:
<div class="ym-fbox">
<label for="correo"> <spring:message
code="registro.form.correo.label"
text="registro.form.correo.label" />
</label>
<form:input path="correo" />
<form:errors path="correo" cssClass="ym-required" element="span" />
</div>
<div class="ym-fbox">
<label for="nickname"> <spring:message
code="registro.form.nickname.label"
text="registro.form.nickname.label" />
</label>
<form:input path="nickname" />
<form:errors path="nickname" cssClass="ym-required" element="span" />
</div>
<div class="ym-fbox">
<label for="contrasena"> <spring:message
code="registro.form.contrasena.label"
text="registro.form.contrasena.label" />
</label>
<form:password path="contrasena" />
<form:errors path="contrasena" cssClass="ym-required" element="span" />
</div>
请帮我解决这个问题!
感谢!!!
答案 0 :(得分:3)
我猜<mvc:interceptors>
不会将拦截器应用于流。尝试将拦截器添加到<FlowHandlerMapping>
。这样的事情(不知道你是否可以简单地引用你在app-servlet.xml
中定义的拦截器):
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="order" value="-1" />
<property name="flowRegistry" ref="flowRegistry" />
<property name="interceptors">
<list>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
p:paramName="lang"/>
</list>
</property>
</bean>