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 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 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
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 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 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 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 creates a JavaBean and adds it to a list. The list of attributes of the item element is given in Table 12.15.
Table 12.15: The item element’s attributes
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