PDA

View Full Version : Can't get Tiles 2 to work with Struts 2


axiopisty
Jun 6th, 2008, 12:36 AM
Hi Everyone,

I've been trying to get Tiles 2 to work with my application for a while now but I'm running into problems. My application currently works fine if I leave tiles out of it. The problem occurs when I try to start my (Tomcat 5.5.26 running on Max OS X {Tiger}) Servlet Container.

The following error only occurs when I include this listener in web.xml:
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>

Jun 5, 2008 10:14:03 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Jun 5, 2008 10:14:03 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/app] startup failed due to previous errors
Jun 5, 2008 10:14:03 PM org.apache.catalina.loader.WebappClassLoader loadClass
INFO: Illegal access: this web application instance has been stopped already. Could not load org.apache.xerces.util.EncodingMap. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
at ...

I followed the instructions at struts.apache.org/2.0.11.1/docs/tiles-plugin

I'm using Maven 2 so I added this to my pom.xml
<!--Tiles-->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles-plugin</artifactId>
<version>2.1.2</version>
</dependency>

These are the other (maybe) relevant dependencies in pom.xml for my app:
<!--Spring-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-hibernate3</artifactId>
<version>2.0.8</version>
</dependency>

<!--Struts-->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.0.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.0.11.1</version>
</dependency>

<!--Hibernate-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.1.GA</version>
</dependency>

As previously mentioned, I placed this in web.xml:
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>

This is a sample of my struts.xml:
...
<struts>
<package name="default" extends="struts-default" namespace="/">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
</result-types>
<!--Gallery-->
<action name="gallery" class="Gallery" method="execute">
<result name="success" type="tiles">gallery.def</result>
</action>
</package>
</struts>

This is /WEB-INF/tiles.xml
...
<tiles-definitions>
<definition name="template.def" template="/template/template.jsp">
<put-attribute name="title" value="Title"/>
<put-attribute name="header" value="/template/header.jsp"/>
<put-attribute name="leftNav" value="/template/leftNav.jsp"/>
<put-attribute name="content" value="/template/content.jsp"/>
<put-attribute name="footer" value="/template/footer.jsp"/>
</definition>
<definition name="gallery.def" extends="template.def">
<put-attribute name="content" value="gallery.jsp"/>
</definition>
</tiles-definitions>

If I need to I will post the JSPs but they are not causing the problem. For some reason adding the listener to web.xml makes it so my application won't start.

Have any of you successfully configured Spring, Struts 2 and Tiles 2? If so, I would greatly appreciate your help.

Thanks,
Axiopisty