What's the simplest way to define a transition that switches the locale and returns to the current view-state? We do have the LocaleChangeInterceptor configured if that helps.
What's the simplest way to define a transition that switches the locale and returns to the current view-state? We do have the LocaleChangeInterceptor configured if that helps.
You call the flow you want to go to (or want to stay), and add &locale=<locale> to the url (if you've configured LocaleChangeInterceptor to read "locale"); the interceptor takes care of the rest.
What's the simplest way to do that from a transition? I'm sorry if I'm being thick here, but it's been a while since I last coded SWF, so it's possible something obvious is escaping me. All I can think of right now is to transition to another view-state that does this, but I was hoping instead for something that could be done right in the transition itself.
You can create a loginBean, and call it in your transition like this:
The bean would have the following method:Code:<transition on="login"> <evaluate expression="loginBean.doLogin()"></evaluate> </transition>
(configure the spring login process as /web/loginProcess, as in the method)Code:public String doLogin() throws IOException, ServletException { ExternalContext context = FacesContext.getCurrentInstance() .getExternalContext(); RequestDispatcher dispatcher = ((ServletRequest) context.getRequest()) .getRequestDispatcher("/web/loginProcess"); dispatcher.forward((ServletRequest) context.getRequest(), (ServletResponse) context.getResponse()); FacesContext.getCurrentInstance().responseComplete(); // It's OK to return null here because Faces is just going to exit. return null; }
The username should be called j_username and the password j_password.
Don't forget to add FORWARD in the Spring security filter like this:
This should do the trick to make use of the default configuration.Code:<filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> <dispatcher>FORWARD</dispatcher> <dispatcher>REQUEST</dispatcher> </filter-mapping>
cheers
What I posted to StackOverflow:
This is not what I was seeking, but it's the only thing I found to do. That is, I created an action method to call from the transition:
<transition on="switchLanguage" validate="false">
<evaluate expression="myAction.switchLanguage"/>
</transition>
And
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();
}
Last edited by breaux; Mar 28th, 2012 at 09:22 AM. Reason: formatting