Dashboard > WebWork > Tutorial > Tiles Use
  WebWork Log In View a printable version of the current page.  
  Tiles Use
Added by Alex Shneyderman, last edited by Philip Luppens on Feb 27, 2006  (view change) show comment
Labels: 
(None)

Here is a simple example of tiles use with spring's TilesConfigurer. There is really no need for spring but tiles definitions must somehow be initialized. If you do not use Spring you could use the following context listener that is exatcly how Spring configures tiles definitions:

package com.opensymphony.webwork.views.tiles;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.struts.tiles.DefinitionsFactoryConfig;
import org.apache.struts.tiles.DefinitionsFactoryException;
import org.apache.struts.tiles.TilesUtil;
import org.apache.struts.tiles.xmlDefinition.I18nFactorySet;

/*
* Modified from spring's source
*
* here's how a smaple web xml should look like:
* <web-app>
*   <context-param>
*     <param-name>tilesDefinitions</param-name>
*     <param-value>/WEB-INF/tiles.xml</param-value>
*   </context-param>
*  
*   <listener>
*      <listener-class>com.opensymphony.webwork.views.tiles.TilesConfigurer</listener-class>
*   </listener>
* </web-app>
*
* To use the definitions specified you would use a dispatcher result (since
* tiles jsp is just another jsp) to render tiles view.
*/
public class TilesConfigurer implements ServletContextListener {

    private boolean initialized = false;
   
    public void contextInitialized (ServletContextEvent evt) {
       
        if (!initialized) {
            DefinitionsFactoryConfig factoryConfig = new DefinitionsFactoryConfig();
            factoryConfig.setFactoryClassname(I18nFactorySet.class.getName());
            factoryConfig.setParserValidate(true);
            factoryConfig.setDefinitionConfigFiles(evt.getServletContext().getInitParameter("tilesDefinitions"));
            try {
                TilesUtil.createDefinitionsFactory(evt.getServletContext(), factoryConfig);
            } catch (DefinitionsFactoryException e) {
                e.printStackTrace();
            }
            initialized = true;
        }
       
    }

    public void contextDestroyed (ServletContextEvent evt) {
    }
   
}

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators