0

我正在使用 Spring MVC 3 和 Spring Webflow 2.3.2 开发一个 Web 应用程序。

我希望能够在流页面上添加 i18n 消息。它在非流页面上工作正常。我可以切换语言,它工作正常。

但是当用户进入网络流时,只显示默认消息。我正在使用<spring:message />标签。

我用谷歌搜索没有成功。

这是我的 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>

请帮我解决这个问题!

谢谢!!!

4

1 回答 1

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>
于 2013-12-16T17:44:40.877 回答