Home

This Chapter
-Chapter 12: The Tiles Framework
-The Problem with JSP Includes
-A Taste of Tiles
-Using JSP Definition Files
-Using XML Definition
-Inheritance of XML Definition
-The Tiles Tag Library’s Tags
-Writing Tiles XML Definition
-Summary

Table of Contents
-Introduction
-Chapter 1: Model 2 and Struts
-Chapter 2: Input Validation with Action Forms
-Chapter 3: The HTML Tag Library
-Chapter 4: Input Validation and Data Conversion
-Chapter 5: The Validator Plugin
-Chapter 6: The Expression Language
-Chapter 7: JSTL
-Chapter 8: The Bean Tag Library
-Chapter 9: The Logic Tag Library
-Chapter 10: Struts-EL, Nested, selectLabel
-Chapter 11: Message Handling and Internationalization
-Chapter 12: The Tiles Framework
-Chapter 13: Securing Struts Applications
-Chapter 14: The Config Object
-Chapter 15: The Persistence Layer
-Chapter 16: Object Caching
-Chapter 17: File Upload and File Download
-Chapter 18: Paging and Sorting
-Chapter 19: Preventing Double Submits
-Chapter 20: Early HttpSession Invalidation
-Chapter 21: Decorating Request Objects
-Chapter 22: How Struts Works

Previous
Next

 

Writing Tiles XML Definition

This section discusses the rules that all XML definition files must comply with.

As specified by the tiles-config_1_1.dtd file, which can be found in the struts.jar file, an XML definition file must have the root element tiles-definition, which is defined as follows.

<!ELEMENT tiles-definitions (definition+)>
<!ELEMENT definition (icon?, display-name?, description?, put*,
  putList*)>
<!ELEMENT put (#PCDATA)>
<!ELEMENT putList ( (add* | item* | bean* | putList*)+) >
<!ELEMENT add (#PCDATA)>
<!ELEMENT bean (set-property*)>
<!ELEMENT item (#PCDATA)>
<!ELEMENT set-property   EMPTY>

The tiles-definition element can have one or many definition elements. The definition element nests an optional icon element, an optional display-name element, an optional description element, zero or many put elements, and zero or many putList elements.

In turn, a putList element can nest any number of add, item, bean, and other putList elements.

Each of the elements is discussed in the following sections.

The tiles-definitions Element

The tiles-definitions element is the root element of every XML definition. It has one or many definition elements. This element does not have any attribute.

The definition Element

The definition element represents a definition that can be inserted in a JSP. Identified by a logical name, a definition is used to define attributes that can be set in the insert tag. The list of attributes of the definition element is given in Table 12.10.

Attribute Description
controllerClass The type of the controller subclass that will be called just before the specified resource is inserted. If this attribute is specified, controllerUrl must not be present.
controllerUrl The context-relative path to the resource used as the controller that will be called immediately before the specified resource is inserted. This attribute must not be present if the controllerClass attribute is specified.
extends Specifies a definition that will become the parent of this definition. All attributes in the parent definition are available to this definition and can be overridden.
name The unique identifier for this definition.
page The same as the path attribute.
path The context-relative path to the resource to insert.
role Specifies a security role that the current user must belong to for this tag to be executed.
template The same as path.

Table 12.10: The definition element’s attributes

The put Element

You use the put element to assign a value to an attribute. The value may be specified in an XML attribute or may be specified in the tag’s body. The list of attributes for put is presented in Table 12.11.

Attribute Description
content The same as the value attribute.
direct The same as type="string".
name The unique identifier for this put element.
type The type of the value, which can be string, page, template, or definition.
value The value to be assigned to the attribute.

Table 12.11: The put element’s attributes

The putList Element

The putList element is used to assign values to a list of attributes. The values must be contained in a java.util.List object and defined in the Tiles configuration file by using an add, item, or putList element. The attribute of putList is given in Table 12.12.

Attribute Description
name The unique identifier for this putList element.

Table 12.12: The putList element’s attribute

The add Element

The add element describes an element of a list. It is similar to put. Table 12.13 lists all the attributes of the add element.

Attribute Description
content The same as the value attribute.
direct The same as assigning string to the type attribute.
type The type of value. The possible values for this attribute are string, page, template, or definition.
value The value to add.

Table 12.13: The add element’s attributes

The bean Element

The bean element is used to create a JavaBean, add it to a List, and create a variable that references the JavaBean. A property of the created JavaBean can be specified using the set-property element. The list of attributes for the bean element is given in Table 12.14.

Attribute Description
id a unique identifier for the JavaBean.
classtype The type of the JavaBean to be created. This is a required attribute.

Table 12.14: The bean element’s attributes

The item Element

The item element creates a JavaBean and adds it to a list. The list of attributes of the item element is given in Table 12.15.

Attribute Description classtype The type for the JavaBean to be created. icon The icon property of the JavaBean. link The link property of the JavaBean. tooltip The tooltip property of the JavaBean. value The value property of the JavaBean.

Table 12.15: The item element’s attributes

The set-property Element

You use the set-property element to set a property of the object specified in the element enclosing the set-property element. For instance, you may have the set-property element inside a bean element. The list of attributes for the set-property element can be found in Table 12.16.

Attribute Description
property The name of the property whose value is to be set.
value The value to set the property with.

Table 12.16: The set-property element’s attributes

Previous
Next