The Tile Configuration File Tags

 < Day Day Up > 



Table 17-1 (above) lists each of the tags used to configure the Tiles configuration file and provides a short description of each tag's purpose.

Table 17-1: Tiles Configuration File Tags

Tag

Description

add

Defines an entry for a list created with the putList tag.

bean

Defines an entry (of the specified type) for a list created with the putList tag.

definition

Defines a 'tile' and assigns a logical name to it.

item

Defines a MenuItem entry for a list created with the putList tag.

put

Defines an attribute (or parameter) for a definition.

putList

Defines a list attribute (of java.util.List type) containing an ordered collection of individual attributes.

set-property

Defines a property and its value for a bean defined with the bean tag.

tiles-definitions

Is the root tag for the Tiles configuration file and thus encapsulates all other tags in the file.

The remainder of this chapter discusses each tag in detail, including a complete description of the tag, the tag's DTD definition, a table that lists each of the tag's attributes (if the tag has attributes), and a usage example for the tag. In the tables that describe each tag's attributes, pay special attention to the Required column, which denotes whether or not the given attribute is required when using the tag. If an attribute is required and you do not specify it when using the tag, the Tiles framework will not be properly configured and, consequently, will not function properly.

The add Tag

The add tag is used to define an entry for a list created with the putList tag. There are two ways that the value for the entry can be specified. The value can be specified with the value attribute, or the value can be placed between opening and closing add tags, as shown next:

<add>value goes here</add>

DTD Definition

Following is the definition for the add tag from the Tiles configuration file DTD:

<!ELEMENT add (#PCDATA)> 

Attributes

Attribute

Description

Required

content

DeprecatedOriginally for compatibility with the now defunct Template Tag Library.Use the value attribute instead.

No

direct

DeprecatedOriginally for compatibility with the now defunct Template Tag Library.Use the type attribute set to 'string' instead.

No

type

Specifies the type (string, page, or definition) of the value. If present, it indicates how the value specified with the value attribute is treated.

No

value

Specifies the value for this entry.

No

Example Usage

The following example illustrates the basic usage of the add tag:

<definition name="mainLayout"             path="/layouts/main.jsp">   <putList name="urls">     <add value="http://www.google.com/"/>     <add value="http://www.yahoo.com/"/>   </putList> </definition>

Each add definition is added to the enclosing list in the order specified.

The bean Tag

The bean tag is used to define an entry (of the specified type) for a list created with the putList tag.

DTD Definition

Following is the definition for the bean tag from the Tiles configuration file DTD:

<!ELEMENT bean (set-property*)> 

Attribute

Attribute

Description

Required

classtype

Specifies the fully qualified class name for the bean.

Yes

Example Usage

The following snippet illustrates how to use the bean tag:

<definition name="mainLayout"             path="/layouts/main.jsp">   <putList name="items">     <bean classtype="org.apache.struts.tiles.beans.SimpleMenuItem">       <set-property property="link" value="aLink1"/>       <set-property property="value" value="aValue1"/>     </bean>   </putList> </definition>

Beans defined with the bean tag can have their properties initialized at creation by nesting set-property tags with the name of the property and the value to be initialized.

The definition Tag

The definition tag is used to define a tile (which is a region within a page) and assign a logical name to it.

DTD Definition

Following is the definition for the definition tag from the Tiles configuration file DTD:

<!ELEMENT definition (icon?, display-name?, description?, put*, putList*)>

Attributes

Attribute

Description

Required

controllerClass

Specifies the fully qualified class name of a controller object that is executed before this definition is inserted.

No

controllerUrl

Specifies the URL for a controller that is executed before this definition is inserted.

No

extends

Specifies the name of another definition that this definition is to extend.

No

name

Specifies the logical name for the definition.

Yes

page

DeprecatedUse the path attribute instead.

No

path

Specifies the URL for the tile.

No

role

Specifies a role to check against the currently authenticated user. If the user is not in the specified role, this definition will not be inserted.

No

template

DeprecatedOriginally for compatibility with the now defunct Template Tag Library.Use the path attribute instead.

No

Example Usage

The following example illustrates the basic usage of the definition tag:

<definition name="mainLayout"             path="/layouts/main.jsp">   <put name="header" value="/layouts/header.jsp"/>   <put name="footer" value="/layouts/footer.jsp"/> </definition>

Each of the attributes nested underneath the definition tag can be accessed by the JSP specified with the path attribute.

The item Tag

The item tag is used to define a MenuItem entry for a list created with the putList tag.

DTD Definition

Following is the definition for the item tag from the Tiles configuration file DTD:

<!ELEMENT item (#PCDATA)> 

Attributes

Attribute

Description

Required

classtype

Specifies the fully qualified class name of the item. If specified, it must be a subclass of org.apache.struts.tiles.beans.MenuItem.

No

icon

Specifies the value to set the bean's icon property to.

No

link

Specifies the value to set the bean's link property to.

Yes

tooltip

Specifies the value to set the bean's tooltip property to.

No

value

Specifies the value to set the bean's value property to.

Yes

Example Usage

The following example illustrates the basic usage of the item tag:

<definition name="mainLayout"             path="/layouts/main.jsp">   <putList name="items">     <item value="Home" link="/index.jsp"/>     <item value="Search" link="/search.jsp"/>   </putList> </definition>

The values specified with the value and link attributes are used to initialize the corresponding properties on the MenuItem object.

The put Tag

The put tag is used to define an attribute (or parameter) for a definition. There are two ways that the value for the attribute can be specified. The value can be specified with the value attribute, or the value can be placed between opening and closing put tags, as shown next:

<put name="header">value goes here</put>

DTD Definition

Following is the definition for the put tag from the Tiles configuration file DTD:

<!ELEMENT put (#PCDATA)> 

Attributes

Attribute

Description

Required

content

DeprecatedOriginally for compatibility with the now defunct Template Tag Library.Use the value attribute instead.

No

direct

DeprecatedOriginally for compatibility with the now defunct Template Tag Library.Use the type attribute set to 'string' instead.

No

name

Specifies the name for the attribute.

Yes

type

Specifies the type (string, page, or definition) of the value. If present, it indicates how the value specified with the value attribute is treated.

No

value

Specifies the value for the attribute.

No

Example Usage

The following example illustrates the basic usage of the put tag:

<definition name="mainLayout"             path="/layouts/main.jsp">   <put name="header" value="/layouts/header.jsp"/>   <put name="footer" value="/layouts/footer.jsp"/> </definition>

Defining attributes with the put tag is as simple as specifying their names and values.

The putList Tag

The putList tag is used to define a list attribute (of java.util.List type) containing an ordered collection of individual attributes. The list can be populated with add, item, or bean definitions or any combination thereof.

DTD Definition

Following is the definition for the putList tag from the Tiles configuration file DTD:

<!ELEMENT putList ((add*|item*|bean*|putList*)+)>

Attribute

Attribute

Description

Required

name

Specifies the name of the list.

Yes

Example Usage

The following example illustrates the basic usage of the putList tag:

<definition name="mainLayout"             path="/layouts/main.jsp">   <putList name="urls">     <add value="http://www.google.com/"/>     <add value="http://www.yahoo.com/"/>   </putList> </definition> 

Each tag nested between opening and closing putList tags will be added to the backing java.util.List instance in the order specified.

The set-property Tag

The set-property tag is used to define a property and its value for a bean defined with the bean tag. The Tiles framework uses reflection to look up and invoke a setter method (e.g., setMyProp( ) for a property called myProp) on the enclosing bean based on the name specified with this tag's property attribute.

DTD Definition

Following is the definition for the set-property tag from the Tiles configuration file DTD:

<!ELEMENT set-property EMPTY>

Attributes

Attribute

Description

Required

property

Specifies the name of the property.

Yes

value

Specifies the value of the property.

Yes

Example Usage

The following example illustrates the basic usage of the set-property tag:

<definition name="mainLayout"             path="/layouts/main.jsp">   <putList name="items">     <bean classtype="org.apache.struts.tiles.beans.SimpleMenuItem">       <set-property property="link" value="aLink1"/>       <set-property property="value" value="aValue1"/>     </bean>   </putList> </definition>

At run time, when the Tiles framework parses a configuration file with a definition similar to this, it will use reflection to look up and invoke the setLink( ) and setValue( ) methods of the class specified by the bean tag's classtype attribute, passing them the defined values.

The tiles-definitions Tag

The tiles-definitions tag is the root tag for the Tiles configuration file and thus encapsulates all other tags in the file. This tag has no other use than to denote the beginning and end of configuration data.

DTD Definition

Following is the definition for the tiles-definitions tag from the Tiles configuration file DTD:

<!ELEMENT tiles-definitions (definition+)>

Example Usage

The following snippet illustrates how to use the tiles-definitions tag:

<tiles-definitions>   <definition …/>   <definition …/>   … </tiles-definitions>



 < Day Day Up > 



Struts. The Complete Reference
Struts: The Complete Reference, 2nd Edition
ISBN: 0072263865
EAN: 2147483647
Year: 2003
Pages: 134
Authors: James Holmes

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net