7 Replies Latest reply on Mar 26, 2015 3:54 PM by aklimets

    i18n value in sling include

    Anzy_cq55

      I am unable to get I18n value in sling include content in 404.jsp/default.jsp.

       

      Basically I am including a 404 page ( based on some template ) into sling/servlet/errorhandler/default.jsp like

      <sling:include path="/content/mysite/en/errorpage" />

       

      I am able to see the included error page in case of 404. But the i18n value that are used in errorpage is not applied, instead i am getting the sling:key as the value itself.

      The standalone page (if i directly open the page instead of going thru 404 error ) shows correct i18n value

      I am using i18n as:

       

      ResourceBundle i18n = slingRequest.getResourceBundle(locale);

      or

      I18n i18n1= new I18n(slingRequest);

       

      Please suggest if i m doing something wrong.

        • 1. Re: i18n value in sling include
          Sham HC Level 7

          Seems like i18n not included in error. Please file a daycare ticket.

          1 person found this helpful
          • 2. Re: i18n value in sling include
            aklimets Adobe Employee

            Yep, the necessary I18nFilter is not included for error handlers: https://issues.apache.org/jira/browse/SLING-2705

            1 person found this helpful
            • 3. Re: i18n value in sling include
              Anzy_cq55 Level 1

              Thanks.

               

              I did some work around for that.  I created a service class and used resourcebundleprovider as a reference . Using the resourcebundleprovider I got the ResourceBundle.

              It worked.

               

              Regards,

              • 4. Re: i18n value in sling include
                sujeetsharma1980

                Hi Anzy,

                 

                I am new to CQ and facing the similiar problem. Can you please share the code snip of service class and its usage in error jsp?

                 

                Regards,

                • 5. Re: i18n value in sling include
                  Dipti Chauhan Level 1

                  Hi

                    i18n filter is not available in case of error handler.You need to add i18n filter in your code.

                  Here is code snip how we implimented this in our code

                  private static ServletRequest getI18nFilters(SlingBindings bindings,HttpServletRequest request,ServletResponse response)

                            {

                                      final Object[] i18nFilters = bindings.getSling().getServices(

                                                          Filter.class,

                                                          "(service.pid=org.apache.sling.i18n.impl.I18NFilter)");

                                      ServletRequest newRequest = request;

                                      if (i18nFilters != null && i18nFilters.length >= 1) {

                                                final class I18nFilterChain implements FilterChain {

                  ServletRequest newRequest = null;

                  @Override

                                                          public void doFilter(final ServletRequest request,

                                                                              final ServletResponse response)

                                                                              throws java.io.IOException, ServletException {

                                                                    newRequest = request;

                                                          }

                  public ServletRequest getWrappedRequest() {

                                                                    return newRequest;

                                                          }

                                                }

                                                // Get i18n filter chain

                                                final Filter i18n = (Filter) i18nFilters[0];

                                                final I18nFilterChain chain = new I18nFilterChain();

                                                try {

                                                          i18n.doFilter(request, response, chain);

                                                } catch (IOException ioException) {

                                                          LOGGER.info("Can not forward to error page" + ioException);

                                                } catch (ServletException servletException) {

                                                          LOGGER.info("Can not forward to error page" + servletException);

                                                }

                                                if (null != chain.getWrappedRequest()) {

                                                          newRequest = chain.getWrappedRequest();

                                                }

                                      } else {

                                                throw new IllegalStateException("No I18NFilter found.");

                                      }

                                      return newRequest;

                  }

                  We used this newly created request for forwand ro error page

                  I hope it will help you

                  • 6. Re: i18n value in sling include
                    sujeetsharma1980 Level 1

                    Thanks Dipti... It seems that you have written a filter. Do I also need to write that, if yes then will I call it? Can you please tell me the flow if any exception occures in JSP?

                    • 7. Re: i18n value in sling include
                      aklimets Adobe Employee

                      There is a workaround noted in this new thread:

                       

                      For CQ5.6, just edit your org.apache.sling.i18n.impl.I18NFilter.config, adding the following line (without spaces):

                      1. sling.filter.scope=["REQUEST","ERROR"]