I have an app using S2, S1, MyFaces, and Tiles. We are using Tiles-2.0.4 in all three modules, so we are not using the Struts-Tiles plugins either in S1 or S2. All pages are Tiles, even the JSF pages. Normally, to use Tiles in S2, you specify the 'type' parameter on the result mappings. However that interferes with dispatching the result to JSF. So getting rid of the Struts-tiles plugins, and having the S2 requests forward to "/SomeTile.tiles" works fine. In fact, based on our success with that, I can't see why anyone would want to use the Plugin. Integrating all these frameworks was a lot of work. The most difficult part was getting I18N messages to work not only in the S1, S2, and JSF pages, but also in back-end modules, which do not have any Struts components or access to the Session. Here is a portion of our web.xml file (pretty big file, sorry):

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
   xmlns="http://java.sun.com/xml/ns/j2ee";
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
       http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";>

<!-- ....... -->
<!-- <context-param>
       <param-name>org.apache.tiles.CONTEXT_FACTORY</param-name>
       <param-value>
           org.apache.tiles.context.enhanced.EnhancedContextFactory
   </param-value>
   </context-param>-->
<!-- Define Tiles config files -->
   <context-param>
       <param-name>
           org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
       </param-name>
       <param-value>
           /WEB-INF/config/tiles_rp.xml,
           /WEB-INF/config/tiles_dm.xml,
           /WEB-INF/config/tiles_pm.xml,
/WEB-INF/config/tiles_as.xml </param-value>
   </context-param>
<!-- use javascript to restore vertical scroll on every request -->
   <context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
       <param-value>server</param-value>
   </context-param>

   <context-param>
       <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
       <param-value>false</param-value>
   </context-param>

   <!-- faces-config.xlm is in standard place (as defined in tomahawk jar)
       - don't want to duplicate
       <context-param>
       <param-name>javax.faces.CONFIG_FILES</param-name>
       <param-value>/WEB-INF/faces-config.xml</param-value>
       </context-param> -->

   <!-- Filter to redirect requests generated by Struts-1 to the
       Struts-2 'Welcome.action', if there is no User login credential
       in the Session. -->
   <filter>
       <description>
           Since the user may bookmark a Struts-1 page, the submitted
           request would not be fully processed by the Struts-2 filter,
           which means that the LoginInterceptor would not be executed,
           with a resultant gaping security hole.  This Filter will
           redirect any request without a User login credential in their
Session. This filter will be mapped to '*.do' to catch requests
           generated by Struts-1 and to '*.jsf' to catch requests generated
           from JSF pages.
       </description>
       <filter-name>LoginRedirectFilter</filter-name>
       <filter-class>
           com.kamakura.struts2.interceptor.LoginRedirectFilter
       </filter-class>
       <init-param>
           <param-name>redirectURL</param-name>
           <param-value>/reports/Welcome.action</param-value>
       </init-param>
   </filter>

   <filter>
       <description>
           This filter executes code to initialize the user, where the
           Request state is "LoggedIn = true" and "Initialized = false".
           The discriminator for "LoggedIn" is the presence in the session
           of a "DBUser" object.  The discriminator for "Initialized" is
           the presence in the session of a Locale object.
The initialization process consists of retrieving the Locale preferences from the ( database / cookies / request ) and storing
           it in the session.
       </description>
       <filter-name> UserInitializerFilter </filter-name>
       <filter-class>
           com.kamakura.struts2.interceptor.UserInitializerFilter
       </filter-class>
   </filter>

   <!-- Filter (Struts-2) -->
   <filter>
       <filter-name>struts2</filter-name>
       <filter-class>
           org.apache.struts2.dispatcher.FilterDispatcher
       </filter-class>
   </filter>

   <filter>
       <display-name>Ajax4jsf Filter</display-name>
       <filter-name>ajax4jsf</filter-name>
       <filter-class>org.ajax4jsf.Filter</filter-class>
   </filter>
<!-- The MyFacesExtensionsFilter is used by some of the more sophisticated
       'Tomahawk' components to provide resources. -->
   <filter>
       <filter-name>MyFacesExtensionsFilter</filter-name>
       <filter-class>
           org.apache.myfaces.webapp.filter.ExtensionsFilter
       </filter-class>
       <init-param>
           <param-name>maxFileSize</param-name>
           <param-value>20m</param-value>
       </init-param>
   </filter>

   <filter-mapping>
       <filter-name>LoginRedirectFilter</filter-name>
       <url-pattern>*.do</url-pattern>
   </filter-mapping>
   <filter-mapping>
       <filter-name>LoginRedirectFilter</filter-name>
       <url-pattern>*.jsf</url-pattern>
   </filter-mapping>
<filter-mapping>
       <filter-name>UserInitializerFilter</filter-name>
       <url-pattern>*.do</url-pattern>
   </filter-mapping>
   <filter-mapping>
       <filter-name>UserInitializerFilter</filter-name>
       <url-pattern>*.action</url-pattern>
   </filter-mapping>
   <filter-mapping>
       <filter-name>UserInitializerFilter</filter-name>
       <url-pattern>*.jsf</url-pattern>
   </filter-mapping>
<!-- Struts-2 filter mapping -->
   <filter-mapping>
       <filter-name>struts2</filter-name>
       <url-pattern>/*</url-pattern>
   </filter-mapping>


   <filter-mapping>
       <filter-name>ajax4jsf</filter-name>
       <servlet-name>Faces Servlet</servlet-name>
   </filter-mapping>
   <filter-mapping>
       <filter-name>MyFacesExtensionsFilter</filter-name>
       <servlet-name>Faces Servlet</servlet-name>
   </filter-mapping>
   <filter-mapping>
       <filter-name>MyFacesExtensionsFilter</filter-name>
       <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
   </filter-mapping>


    <!-- Listener (Struts-2) -->
   <listener>
       <listener-class>
           org.springframework.web.context.ContextLoaderListener
       </listener-class>
   </listener>

<!-- Listener for Tiles-2 -->
   <listener>
         <listener-class>
             org.apache.tiles.web.startup.TilesListener
         </listener-class>
   </listener>

   <!-- Listener for 'MyFaces' jsf components. -->
   <listener>
       <listener-class>
           org.apache.myfaces.webapp.StartupServletContextListener
       </listener-class>
   </listener>

   <!-- Struts-1 Servlet -->
   <servlet>
       <servlet-name>action</servlet-name>
       <servlet-class>
           org.apache.struts.action.ActionServlet
       </servlet-class>
       <!-- <init-param>
           <param-name>chainConfig</param-name>
<param-value>org/apache/struts/tiles/chain-config.xml</param-value>
       </init-param>
       -->
       <init-param>
           <param-name>config</param-name>
           <param-value>/WEB-INF/config/struts-config.xml</param-value>
       </init-param>
       <init-param>
           <param-name>debug</param-name>
           <param-value>false</param-value>
       </init-param>
       <load-on-startup>0</load-on-startup>
   </servlet>
<!-- Tiles-2 Dispatch Servlet -->
   <servlet>
       <servlet-name>Tiles Dispatch Servlet</servlet-name>
       <servlet-class>
           org.apache.tiles.web.util.TilesDispatchServlet
       </servlet-class>
       <load-on-startup>1</load-on-startup>
   </servlet>
<servlet>
       <servlet-name>Faces Servlet</servlet-name>
       <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
       <load-on-startup>3</load-on-startup>
   </servlet>

   <servlet-mapping>
       <servlet-name>action</servlet-name>
       <url-pattern>*.do</url-pattern>
   </servlet-mapping>
<servlet-mapping>
       <servlet-name>Tiles Dispatch Servlet</servlet-name>
       <url-pattern>*.tiles</url-pattern>
   </servlet-mapping>
<servlet-mapping>
       <servlet-name>Faces Servlet</servlet-name>
       <url-pattern>*.jsf</url-pattern>
   </servlet-mapping>

   <!-- The Welcome File List (forwards to Struts-2 'Welcome.action') -->
   <welcome-file-list>
       <welcome-file>html/index.html</welcome-file>
   </welcome-file-list>

   <session-config>
       <session-timeout>30</session-timeout>
   </session-config>


</web-app>

Ray Clough
Software Development
The Kamakura Corporation
2222 Kalakaua Avenue 14th Floor, Honolulu, HI  96815
Phone: 1.808.791.9888 x 8532 Fax: 1.808.791.9898
Email: [EMAIL PROTECTED] Web: www.kamakuraco.com


Chris Pratt wrote:
Are their any examples around that show how to integrate Tiles 2 and
MyFaces?  Even the web.xml and some pointers from someone who's done it
before would be a great help.
 (*Chris*)

Reply via email to