Metadata Tags


The Tiles Configuration File Tags

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 the given attribute is required when using the tag. In addition to the required column denoting whether an attribute is required, the rows for required attributes are highlighted in gray so that you can determine at a glance which attributes are required. 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

Deprecated.

Originally for compatibility with the now-defunct Template Tag Library.

Use the value attribute instead.

No

direct

Deprecated.

Originally 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

Deprecated.

Use 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

Deprecated.

Originally 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 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

Deprecated.

Originally for compatibility with the now-defunct Template Tag Library.

Use the value attribute instead.

No

direct

Deprecated.

Originally 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> 



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

Similar book on Amazon
Struts 2 in Action
Struts 2 in Action
Murach's Java Servlets and JSP, 2nd Edition
Murach's Java Servlets and JSP, 2nd Edition
Jakarta Struts For Dummies
Jakarta Struts For Dummies
Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam
Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam

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