Struts2

I decided to try using sitemesh with struts2. This page lists the problems I encountered during the process and the solutions I found.

Problem: Exception starting filter sitemesh

SEVERE: Exception starting filter sitemesh
com.opensymphony.module.sitemesh.factory.FactoryException: Cannot construct Factory : com.opensymphony.module.sitemesh.factory.DefaultFactory: java.lang.reflect.InvocationTargetException
at com.opensymphony.module.sitemesh.Factory.report(Factory.java:87)

Solution:

created WEB-INF/decorators.xml - the error message doesn't make this at all clear. Google found me the answer after a bit of searching.

Problem: nothing was happening to decorate my pages.

The webapp appeared to start without error, but no decoration was being applied to my pages.

Solution:

I copied sitemesh-decorator.tld, sitemesh-page.tld, and sitemesh.xml to WEB-INF/ (taken from the Struts2 showcase webapp).

The struts-cleanup filter appears to be required.

<filter>
        <filter-name>struts-cleanup</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts-cleanup</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

Also, the order of the filters defined in web.xml seems to make a difference. The order defined in the Struts2 showcase webapp is: -

<filter-mapping>
        <filter-name>struts-cleanup</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

Problem: Unable to find where niftyCorners.css and associated files come from.

Solution:

They seem to be part of the struts2-core jar file, probably generated or served by a Java class. The files are located as follows: -

./struts2-core-2.0.6/org/apache/struts2/static/niftycorners/nifty.js
./struts2-core-2.0.6/org/apache/struts2/static/niftycorners/niftyCorners.css
./struts2-core-2.0.6/org/apache/struts2/static/niftycorners/niftylayout.css
./struts2-core-2.0.6/org/apache/struts2/static/niftycorners/niftyPrint.css

I'm still not sure how these get magically wired up to the /struts/niftycorners URL pattern.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.