Getting started
This tutorial describes how to use the Tiles framework to create reusable presentation components. (At its creation, the Tiles framework was originally called Components. The name was changed because "components" means too many different things, but the spirit of the original name remains.) Beyond site layouts, however, you can do much more with tiles. You can, for example, compartmentalize your presentation tier to better reuse layouts, HTML, and other visual components.
This tutorial strives to impart the basics of using the Tiles framework, then takes your knowledge up a notch. By the time you finish, you will be able to use the more advanced Tiles features to create reusable components.
Note: Throughout this tutorial, the terms tile and page are used interchangeably because any Web resource can be a tile. A tile layout represents a special type of tile you can use to place other tiles within it. A tile layout can be used as a tile in another tile layout.
Getting down to specifics, this tutorial:
- Defines the Tiles framework and architecture.
- Covers the Tiles architecture and how it integrates with Struts.
- Clarifies key Tiles concepts.
- Demonstrates how to build and use a tile layout as a site template.
- Demonstrates how to use tile definitions both in XML and JavaServer Pages (JSP) code.
- Defines tile scope and how to move objects in and out of tile scope.
- Works with attribute lists.
- Shows how to nest tiles.
- Demonstrates how to build and use a tile layout as a small visual component.
- Shows how to subclass a definition.
- Creates a controller for a tile.
- Demonstrates using a tile as an
ActionForward.
Who should take this tutorial?
If you find yourself writing the same three lines of JSP code on every page, or you want to define complex template layouts easily, then you will benefit from this tutorial.
This tutorial assumes you have a solid understanding of Java programming, MVC (Model-View-Controller), Model 2, and JSP technology. While a good Struts background lets you get the most out of this tutorial, if you're adept at JSP programming, you should be able to follow most of what is going on.
Software requirements and code installation
To complete this tutorial, you will need:
- A 1.1, 1.2, or 2.0 JSP-compliant servlet/JSP container. Apache Tomcat 3.x or higher is an excellent choice. Note: The tutorial's examples were written with a JSP 1.2-compliant container.
- The Tiles framework. You can get the framework as part of the Struts 1.1 download or standalone from the Tiles Web site.
- The source code. I've supplied two versions: one with jar files and one without jar files for those of us who are bandwidth impaired. Struts ships with a blank war file,
struts-blank.war(under thewebappsdirectory), which illustrates which configuration files and jar files you need, and where you typically put them. You'll use the same structure for the example code.
See Resources for information on these materials and additional resources.

