Struts: The Complete Reference, 2nd Edition

Tiles Overview

Before getting into the details of using the Tiles framework, it's necessary to give an overview of how Tiles works. Tiles allows you to exploit the concept of JSP includes by providing a framework for defining and dynamically populating page layouts. Each page layout is simply a JSP that defines a template frame (or outline) with placeholders for where content should go. At run time, Tiles replaces the placeholders with their associated content, creating a complete page and unique instance of the layout. To accomplish this, Tiles uses its concepts of definitions and attributes.

A Tiles definition creates a piece of content that Tiles can insert into a JSP using that definition's name. Each definition consists of a name (or identifier), a layout JSP, and a set of attributes associated with the definition. Once defined, a definition can be included in a page or, as is most often the case, be used as the target of a Struts forward. In both cases, when the definition is encountered, Tiles passes to the layout JSP specified by the definition the set of attributes that were declared for that definition. An attribute value can be the path to a JSP, a literal string, or a list of either.

To facilitate the use of definitions and attributes, Tiles uses an XML configuration file (typically named tiles-defs.xml) for storing their definitions. Tiles also provides a JSP tag library for defining definitions and attributes. Additionally, the Tiles Tag Library is used for inserting attributes into JSPs.

Категории