如果有帮助,我们确实配置了LocaleChangeInterceptor
。
(最初发布到http://forum.springsource.org/showthread.php?123391-Transition-to-set-locale)
答案 0 :(得分:1)
这不是我想要的,但这是我发现的唯一的事情。也就是说,我创建了一个从转换中调用的动作方法:
<transition on="switchLanguage" validate="false">
<evaluate expression="myAction.switchLanguage"/>
</transition>
和
public Event switchLanguage(RequestContext context)
{
// get the "other" locale string itself from the current locale's resource bundle
Locale locale = context.getExternalContext().getLocale();
MessageSource ms = context.getActiveFlow().getApplicationContext();
String newLocaleString = ms.getMessage("lang.other", null, locale);
HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getNativeRequest();
HttpServletResponse res = (HttpServletResponse) context.getExternalContext().getNativeResponse();
LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(req);
localeResolver.setLocale(req, res, StringUtils.parseLocaleString(newLocaleString));
return success();
}
答案 1 :(得分:1)
最好是使用现有组件。这是Spring WebFlow的片段,配置为使用“LocaleChangeInterceptor”:
@Bean
public FlowHandlerMapping flowHandlerMapping(FlowDefinitionRegistry flowDefinitionRegistry) {
FlowHandlerMapping handlerMapping = new FlowHandlerMapping();
handlerMapping.setInterceptors(new Object[] { localeChangeInterceptor() });
// ... other configuration
return handlerMapping;
}
/**
* @category locale_switcher
*/
@Bean
public SessionLocaleResolver localeResolver() {
SessionLocaleResolver localeResolver = new SessionLocaleResolver();
localeResolver.setDefaultLocale(Locale.ENGLISH);
return localeResolver;
}
/**
* @category locale_switcher
*/
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
localeChangeInterceptor.setParamName("lang");
return localeChangeInterceptor;
}
工作原理:
http://localhost:8080/myflow?execution=e1s1&lang=en