Hi,
I am trying Struts 2.1.6 with Freemarker Sitemesh decorators. I am getting a
NPE in the PageFilter HeadTag class. When debugging it seems the getPage()
call in the class returns Null. This only happens for the decorator:head and
not for the body or title (If I remove the <@decorator.head/> from my
decorator it works fine). The error is:

<code>
java.lang.NullPointerException
        at
com.opensymphony.module.sitemesh.taglib.decorator.HeadTag.doEndTag(HeadTag.java:33)
        at
freemarker.ext.jsp.TagTransformModel$TagWriter.endEvaluation(TagTransformModel.java:431)
        at
freemarker.ext.jsp.TagTransformModel$TagWriter.onStart(TagTransformModel.java:370)
        at freemarker.core.Environment.visit(Environment.java:295)
        at freemarker.core.UnifiedCall.accept(UnifiedCall.java:130)
        at freemarker.core.Environment.visit(Environment.java:209)
        at freemarker.core.MixedContent.accept(MixedContent.java:92)
        at freemarker.core.Environment.visit(Environment.java:209)
        at freemarker.core.Environment.process(Environment.java:189)
        at freemarker.template.Template.process(Template.java:237)
        at
org.apache.struts2.sitemesh.FreeMarkerPageFilter.applyDecorator(FreeMarkerPageFilter.java:160)
        at
org.apache.struts2.sitemesh.TemplatePageFilter.applyDecorator(TemplatePageFilter.java:116)
        at
com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:62)
</code>


I have tried to use the standard SiteMeshFilter instead of the
FreeMarkerPageFilter and then I dont encounter any problem. But of course I
can't access the struts value stack anymore, so I need to get the
FreemarkerPageFilter working. Has anyone been successful in this
combination?

The relevant part of my web.xml looks like this:
<code>
    <display-name>struts2test</display-name>
    <filter>
        <filter-name>struts-cleanup</filter-name>
       
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
    </filter>
    <filter>
        <filter-name>sitemesh</filter-name>
       
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
        <!-- 
           
<filter-class>org.apache.struts2.sitemesh.FreeMarkerPageFilter</filter-class>
        -->
    </filter>
    <filter>
        <filter-name>struts</filter-name>
       
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        <init-param>
            <param-name>actionPackages</param-name>
            <param-value>com.specieslog.action</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>struts-cleanup</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>
    <filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    
    
    <!-- Servlets -->
    <servlet>
        <servlet-name>jspSupportServlet</servlet-name>
    
<servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
        <load-on-startup>5</load-on-startup>
    </servlet>
    
    <servlet>
        <servlet-name>sitemesh-freemarker</servlet-name>
       
<servlet-class>com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet</servlet-class>
        <init-param>
            <param-name>TemplatePath</param-name>
            <param-value>/</param-value>
        </init-param>
        <init-param>
            <param-name>default_encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>    
    <servlet-mapping>
        <servlet-name>sitemesh-freemarker</servlet-name>
        <url-pattern>*.dec</url-pattern>
    </servlet-mapping>    
</code>


My struts.xml is this minimal one, making Freemarker the default result
type:
<code>
        <package name="default" namespace="/" extends="struts-default">
            <result-types>
                <result-type name="freemarker"
class="org.apache.struts2.views.freemarker.FreemarkerResult"
default="true"/>
            </result-types>
            <action name="hello" class="org.gbif.action.IndexAction">
                <result>/WEB-INF/pages/hello.ftl</result>
            </action>
        </package>
</code>


I have also tried 2 different sitemesh page parsers, HTMLPageParser and
FastPageParser, but that didnt help either.

Ah, and this is the decorator I am using:
<code>
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<#assign
decorator=JspTaglibs["http://www.opensymphony.com/sitemesh/decorator";] />
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
        <title><@decorator.title default="Struts2 Freemarker Sitemesh
Hibernate"/></title>
        <@decorator.head/>
</head>
<body>
<div id="main">
        <@decorator.body/>
</div> <!-- /main -->
</body>
</html>
</code>

Any idea highly appreciated!

Markus


-- 
View this message in context: 
http://www.nabble.com/Struts-2.1.6%2C-Sitemesh---FreeMarkerPageFilter-tp21739507p21739507.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to