Announcement Announcement Module
No announcement yet.
Transition to set locale Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transition to set locale

    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.

  • #2
    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.


    • #3
      Understood, but...

      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.


      • #4
        You can create a loginBean, and call it in your transition like this:
        <transition on="login">
        			<evaluate expression="loginBean.doLogin()"></evaluate>
        The bean would have the following method:
        public String doLogin() throws IOException, ServletException {
        		ExternalContext context = FacesContext.getCurrentInstance()
        		RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
        		dispatcher.forward((ServletRequest) context.getRequest(),
        				(ServletResponse) context.getResponse());
        		// It's OK to return null here because Faces is just going to exit.
        		return null;
        (configure the spring login process as /web/loginProcess, as in the method)
        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.



        • #5
          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"/>


          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, 09:22 AM. Reason: formatting