Menu

autoInclude and JSPTagLibs

Help
2008-10-29
2013-05-30
  • Davide Cavestro

    Davide Cavestro - 2008-10-29

    I am experiencing some problems when I use the Configuration addAutoInclude method to automatically include a template that acts as an header for every other template.

    If the included template contains a JSP tag call, an exception is thrown, otherwise it works fine.
    The same template works fine, even with the jsp tag, when directly included via a directive (and not the autoinclude) like this:

    ...
    <#include "TemplatesHeader.ftl">
    ...

    This is the included template content:
    ...
       <#assign fmt=JspTaglibs["http://java.sun.com/jsp/jstl/fmt"]>
       <@fmt.setLocale value=fmtSetLocaleValue variant=fmtSetLocaleVariant/>

    It uses a JSP tag, and the following exception is always thrown:

    java.lang.NullPointerException
        at freemarker.ext.jsp.PageContextFactory.getCurrentPageContext(PageContextFactory.java:49)
        at freemarker.ext.jsp.TagTransformModel.getWriter(TagTransformModel.java:100)
        at freemarker.core.Environment.visit(Environment.java:284)
        at freemarker.core.UnifiedCall.accept(UnifiedCall.java:130)
        at freemarker.core.Environment.visit(Environment.java:208)
        at freemarker.core.MixedContent.accept(MixedContent.java:92)
        at freemarker.core.Environment.visit(Environment.java:208)
        at freemarker.core.Environment.include(Environment.java:1477)
        at freemarker.template.Configuration.doAutoIncludes(Configuration.java:945)
        at freemarker.template.Template.createProcessingEnvironment(Template.java:369)
        at freemarker.template.Template.process(Template.java:237)
        at org.springframework.web.servlet.view.freemarker.FreeMarkerView.processTemplate(FreeMarkerView.java:344)
        at org.springframework.web.servlet.view.freemarker.FreeMarkerView.doRender(FreeMarkerView.java:280)
        at org.springframework.web.servlet.view.freemarker.FreeMarkerView.renderMergedTemplateModel(FreeMarkerView.java:225)
        at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:174)
        at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:252)

     
    • Davide Cavestro

      Davide Cavestro - 2008-10-29

      What's wrong with that?
      It could be my fault, but it seems like the autoinclusion creates a short-circuit in the environment initialization process, cause the
      freemarker.template.Template.createProcessingEnvironment(Template.java:369)
      line is creating the Environment, but to init it has to process the included template, that wants an Environment to create a PageContext... but the Environment is still in initialization phase.

      Some ideas?
      Thank you

       
      • Nobody/Anonymous

        I know nothing about this issue, however one thing is sure: createProcessingEnvironment must not process (i.e., execute) any pice of template, be it an automatic inclusion or not. If it indeed does, well, that's a fat bug then.

         
        • Davide Cavestro

          Davide Cavestro - 2008-10-29

          I agree with you.
          On the other hand, looking at the stack trace I see that createProcessingEnvironment causes (indirectly) the call of getWriter. I think the writer is likely used to render some processing output.

          at freemarker.ext.jsp.PageContextFactory.getCurrentPageContext(PageContextFactory.java:49)
          at freemarker.ext.jsp.TagTransformModel.getWriter(TagTransformModel.java:100)
          ...
          at freemarker.core.MixedContent.accept(MixedContent.java:92)
          at freemarker.core.Environment.visit(Environment.java:208)
          at freemarker.core.Environment.include(Environment.java:1477)
          at freemarker.template.Configuration.doAutoIncludes(Configuration.java:945)
          at freemarker.template.Template.createProcessingEnvironment(Template.java:369)

          Another remarkable thing is that when I remove the jsp tag from the template, everything works.

          Kind regards
          Davide

           
        • Attila Szegedi

          Attila Szegedi - 2008-10-29

          This is indeed a bug. There's no reason for Environment.getCurrentEnvironment() to *not* return the relevant Environment object when the autoincludes are executed.

          I'll fix this shortly.

           
          • Attila Szegedi

            Attila Szegedi - 2008-10-29

            Alright, this should be fixed. If you can, replace your freemarker.jar with this one and give it a try:

            http://freemarker.org:8085/download/FM-BRANCH23/artifacts/build-103/Library/freemarker.jar

            This'll eventually get published as FreeMarker 2.3.15.

             
            • Davide Cavestro

              Davide Cavestro - 2008-10-30

              Great!
              I confirm that your patch resolve the problem.
              I've tried it and everything works fine.

              I'll wait for the 2.3.15 to permanently replace the freemarker library.

              Thank you very much for your quick intervention.

              Kind regards
              Davide

               

Log in to post a comment.

MongoDB Logo MongoDB