The Tiles Document Assembly Framework
Tiles builds on the "include" feature provided by the JavaServer Pages
specification to provide a full-featured, robust framework for assembling
presentation pages from component parts. Each part ("Tile") can be
reused as often as needed throughout your application. This reduces the
amount of markup that needs to be maintained and makes it easier to
change the look and feel of a website.
Overview of Tiles Features
Create a screen by assembling Tiles, e.g. header, footer, menu, body
Definitions can take place:
in a centralized XML file
directly in JSP pages
Definitions provide an inheritance
mechanism: a definition can extend another one
and override some (or all) of its parameters
Define common page layouts and reuse them across your website
Define menu layouts and pass lists of items and links
Define a portal layout, use it by passing list of Tiles (pages) to show
Reuse existing layouts, or define your own ones
Dynamic page building
Tiles are gathered dynamically during page reload. It is possible to change any attributes: layout, list of Tiles in portal, list of menu items, ...
Reuse of Tiles/Components
If well defined, a Tile can be reused in different locations
Dynamic attributes are used to parameterize Tiles
It is possible to define libraries of reusable Tiles
Build a page by assembling predefined components, give them appropriate parameters
It is possible to load different Tiles according to the user's Locale
A mechanism similar to Java properties files is used for definition files: you can have one definition file per Locale, the appropriate definition is loaded according to the current Locale
It is possible to load different Tiles according to a key stored e.g. in session context
The key could hold e.g. user privileges, browser type, ...
A mechanism similar to Java properties files is used for definition files: you can have one definition file per key, the appropriate definition is loaded according to the key
Enabling your application for Tiles
Tiles is bundled with the framework but not enabled by default. To enable Tiles you need to:
Setup the struts-tiles taglib in your
WEB-INF/web.xml file to include the following tag library declaration:
At the top of each JSP page that will use the Tiles custom tags, add the following line declaring the Tiles custom tag library for use on the page:
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
: You can omit the declaration in
and replace above line with the full URI:
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
If you plan to use Tiles definitions defined in a centralized file, you need to create this file and instruct the framework to load the Tiles plugin which will create the factory corresponding to the file. You can have more than one definitions file.
Create a file containing your definitions (e.g.
WEB-INF/tiles-defs.xml). You can use the
tiles-defs.xml file from the Tiles application for a detailed example of the required syntax.
Setup the Tiles plugin in each
struts-config.xml file corresponding to a module:
<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml,
<set-property property="definitions-parser-validate" value="true" />
<set-property property="moduleAware" value="true" />
Note: This plugin creates one factory for each module. The plugin first reads the factory parameters from
web.xml and then overloads them with the ones defined in the first
Note: The Tiles framework now uses the commons-logging package to output different information or debug statements. Please refer to this package documentation to enable it. The simplest way to enable logging is to create two files in
# Logging detail level,
# Must be one of ("trace", "debug", "info", "warn", "error", or "fatal").