Announcement Announcement Module
No announcement yet.
Forwarding Locale change from JSF to Spring Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Forwarding Locale change from JSF to Spring


    I'm stuck with my problem. I have a Web App with JSF and Spring Security.
    A user can switch a UI language. The Locale is stored in JSF like this:
    Now I would like to propagate the locale change to Spring Security to display localized messages in case of failed authorization/authentication.

    My Spring Securty messages are managed in a Spring bean of urceBundleMessageSource.

    The problem is, after changing the Locale, the RequestContextListener reads the new Locale from HTTPRequest and sets it to org.springframework.context.i18n.LocaleContextHold er. HTTPRequest is not aware of the Locale change. (JSF does not set it into HTTPRequest - I don't know why - maybe it's "as designed") .

    So till now I considered several ways to forward the Locale change from JSF to Spring all with no success:
    1. Set Locale to LocaleContextHolder where I set it for FacesContext: somehow it is another instance of LocaleContextHolder than the one I get in my AuthenticationProvider - it must be a thread or life-cycle issue
    2. Override a requestInitialized method in RequestContextListener and set there Locale to LocaleContextHolder read from FacesContext: FacesContext.getCurrentInstance() is null
    3. Implement a custom javax.faces.event.PhaseListener and set the Locale in beforePhase(PhaseEvent aEvent) : aEvent.getFacesContext().getViewRoot() is null

    Another option that I have not tried yet would be to create a custom javax.servlet.Filter and set the right Locale modifying the HTTPRequest (I expected JSF would do it for me) so that RequestContextListener could set the right one to LocaleContextHolder. Or I could just try to save the Locale into HTTPSession on JSF side to get it on the Spring side.
    I don't believe I'm the first one facing this problem. What is a common way to integrate JSF and Spring in this particular aspect (localization)?

    Many thanks in advance !


    P.S. I have just tried the last thing with the custom Filter: failure again - FacesContext.getCurrentInstance() is null.
    I see no other possibility as to interchange the desired Locale via HTTPSession. Some ideas?
    Last edited by andrewz; Aug 1st, 2008, 10:25 AM. Reason: P.S.