开发者

accessing HttpServletRequest object in Spring WebFlow

I am using WebFlow and would like to add the current Locale into the flow. I already have a resolveLocale method that does this with this signature:

public Locale resolveLocale (HttpServletRequest request);

I would like to add something like this in my WebFlow XML:

<on-start>
<evaluate expression="localeService.resolveLocale(???)" result="flowScope.locale"/>
</开发者_JS百科on-start>

Now, I don't know what to put in the ??? parameter part.

Any ideas? Thanks for reading.


I haven't used Web Flow, but presuming it's similar to the rest of Spring, you can use the RequestContextHolder for this. A quick Google search suggests that Web Flow even gives you a web flow specific RequestContextHolder - even better


An easier way to access the locale is spring's LocaleContextHolder

Just call: LocaleContextHolder.getLocale()

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


you can get HttpServletRequest in this style

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


Thanks for your hints. I'm using the following line in my service (my SWF-config uses the SessionLocaleResolver):

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜