1 Reply Latest reply on Jan 19, 2007 12:50 PM by Peter Halverson

    Layout I18N: wrong locale in JSP

    Peter Halverson Newbie

      We need to internationalize the contents of our layout templates (page titles, some running text, injection of language-specific stylesheets), but the Locale set in the LocaleInterceptor (based on session, cookies, user preference) is not being propagated to the request received by the layout JSP.

      Looking at org.jboss.portal.theme.impl.JSPLayout, it seems this is because the layout dispatcher is being passed the original client request, as opposed to a request object with the preferred locales augmented by the LocaleInterceptor. My grasp of the various request objects flowing around the system is tenous, so I'm not quite sure what the right solution should be here.

      Any suggestions?

      p

      JBoss Portal 2.4.1
      Custom LocaleInterceptor
      JBoss AS 4.0.4

        • 1. Re: Layout I18N: wrong locale in JSP
          Peter Halverson Newbie

          For now, I've defined a custom PortalLayout class which passes the correct locale to the JSP (using an HttpServletRequestWrapper), and specify this class in my layouts file using the (undocumentated) "layout-implementation" attribute. Seems to work. Still unclear on the rationale for passing the original client request down.

          p

          public class LocalizingLayoutImpl extends PortalLayout {
          
           public void assembleResponse(ServerRequest request,
           ServerResponse response,
           MarkupResult markupResult)
           throws ServletException, IOException
           {
           HttpServletRequest httpRequest = request.getContext().getClientRequest();
           HttpServletResponse httpResponse = response.getContext().getClientResponse();
           RenderContext renderCtx = getRenderContext(response.getStreamInfo(), request, markupResult);
           LayoutDispatcher dispatcher = new LayoutDispatcher(renderCtx, new LocalizedRequest(httpRequest, request), httpResponse, markupResult);
           dispatcher.include();
           }
          
           private class LocalizedRequest extends HttpServletRequestWrapper {
          
           private ServerRequest serverRequest;
          
           public LocalizedRequest(HttpServletRequest request, ServerRequest serverRequest) {
           super(request);
           this.serverRequest = serverRequest;
           }
          
           @Override
           public Locale getLocale() {
           Locale locale = serverRequest.getLocale();
           if (locale == null) {
           return super.getLocale();
           }
           else {
           return locale;
           }
           }
          
           @Override
           public Enumeration getLocales() {
           final Locale[] locales = serverRequest.getLocales();
           if (locales == null) {
           return super.getLocales();
           }
           else {
           return new Enumeration() {
           private int index = 0;
          
           public boolean hasMoreElements() {
           return index < locales.length;
           }
          
           public Object nextElement() {
           return locales[index++];
           }
          
           };
           }
           }
          
           }
          }