【问题标题】:accessing HttpServletRequest object in Spring WebFlow在 Spring WebFlow 中访问 HttpServletRequest 对象
【发布时间】:2010-10-13 16:15:13
【问题描述】:

我正在使用 WebFlow,并希望将当前语言环境添加到流中。 我已经有一个使用此签名执行此操作的 resolveLocale 方法:

public Locale resolveLocale (HttpServletRequest request);

我想在我的 WebFlow XML 中添加类似的内容:

<on-start>
<evaluate expression="localeService.resolveLocale(???)" result="flowScope.locale"/>
</on-start>

现在,我不知道该放什么???参数部分。
有任何想法吗?感谢阅读。

【问题讨论】:

    标签: java spring-webflow


    【解决方案1】:

    我没有使用过 Web Flow,但假设它与 Spring 的其余部分类似,您可以使用 RequestContextHolder。快速的 Google 搜索表明 Web Flow 甚至为您提供了web flow specific RequestContextHolder - 甚至更好

    【讨论】:

      【解决方案2】:

      更简单的访问语言环境的方法是 spring 的 LocaleContextHolder

      只需调用:LocaleContextHolder.getLocale()

      http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/context/i18n/LocaleContextHolder.html

      【讨论】:

        【解决方案3】:

        你可以用这种风格获取HttpServletRequest

        (HttpServletRequest)RequestContextHolder.getRequestContext().getExternalContext().getNativeRequest()
        

        【讨论】:

          【解决方案4】:

          感谢您的提示。我在我的服务中使用以下行(我的 SWF 配置使用 SessionLocaleResolver):

          Locale locale = (Locale) RequestContextHolder.getRequestAttributes().getAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, RequestAttributes.SCOPE_SESSION);
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2011-03-04
            • 2012-04-03
            • 1970-01-01
            • 2012-01-21
            • 2011-12-13
            • 2017-06-13
            • 2013-11-25
            • 1970-01-01
            相关资源
            最近更新 更多