~~ $Id$ ~~ ~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ~~ ----------- Tiles Configuration ----------- Configuring Tiles Your application needs to be configured to work with Tiles. There are various options, depending on your needs, your application type, etc. Starting Tiles in a web application Tiles has always been a web application package, usually used in conjunction with Struts. Tiles 2 evolved to the point of being technology-independent, but its use in a Servlet-based web application will be the most frequent use case. * Starting Tiles engine To start Tiles you can use pure {{{configuration.html#Startup_with_Java_code}Java initialization}} or the original {{{configuration.html#Startup_with_initialization_parameters}initialization-parameter-based initialization}}. In both cases, you have two options, just choose what is the best for your needs: * Load the <> at startup. You can do it by specifying it in your <<>> file: -------------------------- tiles org.apache.tiles.web.startup.TilesServlet ... 2 -------------------------- Note: The Tiles servlet is just a startup servlet and <>. Therefore, a mapping is not needed. * Load the <>. Specify it in your <<>> file: ------------------------------- org.apache.tiles.web.startup.TilesListener ------------------------------- ** {Startup with Java code} To startup with Java code, extend <<>> or <<>> and override the <<>> method: -------------------------- protected TilesInitializer createTilesInitializer() { return new MyCustomTilesInitializer; } -------------------------- ** {Startup with initialization parameters} You can configure Tiles by using initialization parameters, like in Tiles 2.0.x. If you use <<>>, you can use <<>> elements: -------------------------- tiles org.apache.tiles.web.startup.TilesServlet org.apache.tiles.definition.DefinitionsFactory.DEFINITIONS_CONFIG /WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml 2 -------------------------- As you can see, the init parameter <<>> specifies the path of the {{{basic/index.html}Tiles configuration files}}. You can specify it also as a context parameters. If you use <<>>: ------------------------------- org.apache.tiles.web.startup.TilesListener ------------------------------- you can specify the Tiles configuration files using a context parameter: ------------------------------- org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG /WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml ------------------------------- Starting Tiles in a portlet application TBD Configuring Tiles internals * {Pure Java configuration} In both environments, it is possible to use pure <>, without messing with the deployment descriptors. You have two choices of configuration: * By using a custom {{{../apidocs/org/apache/tiles/startup/TilesInitializer.html}TilesInitializer}}, for example by overriding {{{../apidocs/org/apache/tiles/startup/BasicTilesInitializer.html}BasicTilesInitializer}} methods. * By using a subset of initialization parameters and extending {{{../apidocs/org/apache/tiles/factory/AbstractTilesContainerFactory.html}AbstractTilesContainerFactory}}, {{{../apidocs/org/apache/tiles/context/AbstractTilesApplicationContextFactory.html}AbstractTilesApplicationContextFactory}} or both. This option can be combined with the first. ** Custom Tiles container factory You have to do create a class that extends {{{../apidocs/org/apache/tiles/factory/AbstractTilesContainerFactory.html}AbstractTilesContainerFactory}}. In particular you can use {{{../apidocs/org/apache/tiles/factory/BasicTilesContainerFactory.html}BasicTilesContainerFactory}} as a basis for your extended configuration. <<>> is the configuration that replicates the default configuration of Tiles, i.e. the one that assumes when no additional parameter is provided. The {{{../apidocs/org/apache/tiles/factory/BasicTilesContainerFactory.html}Javadoc documentation of BasicTilesContainerFactory}} documents all the methods that can be overridden to use your own configuration. To enable pure Java configuration, provide the {{{../config-reference.html#org.apache.tiles.factory.AbstractTilesContainerFactory}<<>>}} parameter this way: -------------------------------- org.apache.tiles.factory.AbstractTilesContainerFactory org.apache.tiles.test.factory.TestTilesContainerFactory -------------------------------- Where <<>> is a class that extends <<>>. ** Custom Tiles application context factory You have to do create a class that extends {{{../apidocs/org/apache/tiles/context/AbstractTilesApplicationContextFactory.html}AbstractTilesApplicationContextFactory}} In particular you can use {{{../apidocs/org/apache/tiles/servlet/context/ServletTilesApplicationContextFactory.html}ServletTilesApplicationContextFactory}} as a basis for your extended configuration under a servlet environment. To enable pure Java configuration for the Tiles application context, provide the {{{../config-reference.html#org.apache.tiles.context.AbstractTilesApplicationContextFactory}<<>>}} parameter this way: -------------------------------- org.apache.tiles.context.AbstractTilesApplicationContextFactory org.apache.tiles.test.context.TestTilesApplicationContextFactory -------------------------------- Where <<>> is a class that extends <<>>. * Configuration through initialization parameters You can configure Tiles internal behaviour by specifying: * in a web application environment, by using context parameters or init parameters of TilesServlet or TilesFilter; * in a portlet environment, by using portlet init parameters. For the details see {{{../config-reference.html}Tiles configuration reference}}.