~~ $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. ~~ ----------- Creating Tiles Pages ----------- Creating and using Tiles pages After installing and learning some of Tiles concepts, it is time to create some pages. Here you will find the steps to create reusable Tiles pieces and complete pages. * Create a template Let's take the <> page structure: [../../images/tiled_page.png] The "classic layout", a typical structure of a web page. Create a JSP page that acts as this layout and place it under <<>> file. ------------------------------- <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %> <tiles:getAsString name="title"/>
------------------------------- This template has five attributes: <<>> (of <<<string>>> type), <<<header>>>, <<<menu>>>, <<<body>>> and <<<footer>>>. * Create the composing pages In this phase, you have to create four JSP pages, that will take place of <<<header>>>, <<<menu>>>, <<<body>>> and <<<footer>>> attributes in the previously created template. You can put everything you want in this pages, they are just a test. * Create a definition Supposing that you configured Tiles, in <<<web.xml>>>, to startup using the <<<TilesServlet>>>, you need to specify what will be the files containing the Tiles definitions to load: ------------------------------------ <servlet> <servlet-name>tiles</servlet-name> <servlet-class>org.apache.tiles.servlet.startup.TilesServlet</servlet-class> <init-param> <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name> <param-value>/WEB-INF/tiles-defs.xml</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> ------------------------------------ Create the <<</WEB-INF/tiles-defs.xml>>> file: ------------------------------------ <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" "http://tiles.apache.org/dtds/tiles-config_2_1.dtd"> <tiles-definitions> <definition name="myapp.homepage" template="/layouts/classic.jsp"> <put-attribute name="title" value="Tiles tutorial homepage" /> <put-attribute name="header" value="/tiles/banner.jsp" /> <put-attribute name="menu" value="/tiles/common_menu.jsp" /> <put-attribute name="body" value="/tiles/home_body.jsp" /> <put-attribute name="footer" value="/tiles/credits.jsp" /> </definition> </tiles-definitions> ------------------------------------ * Render the definition After creating the definition, you can render it: * by using the <<<\<tiles:insertDefinition /\>>>> tag, inserting it in a JSP page: ------------------------------------- <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %> <tiles:insertDefinition name="myapp.homepage" /> ------------------------------------- * in other cases, you can render directly in the response, by using the Tiles container: ----------------------------------- TilesContainer container = TilesAccess.getContainer( request.getSession().getServletContext()); container.render("myapp.homepage", request, response); ----------------------------------- * by using {{{../advanced/utils.html}Rendering Utilities}} provided by Tiles. * by using a supporting framework. See {{{../integration/index.html}Integrations}} for a list of supporting frameworks.