The Velocity Project < Velocity Tools - Struts >

Velocity Tools

VelocityStruts

VelocityStruts Tools

Other Subprojects

TilesTool Reference Documentation
       

The TilesTool is used to interact with the Tiles framework that is now part of Struts (since v. 1.1).

Class
 org.apache.velocity.tools.struts.TilesTool
Name
 $tiles (this is the recommended name of the tool in the Velocity context)
Toolbox Configuration Example
 
<tool>
  <key>tiles</key>
  <scope>request</scope>
  <class>org.apache.velocity.tools.struts.TilesTool</class>
</tool>
Author(s)
  Marino A. Jonsson
Method Overview
importAttributes() Imports all attributes in the current tiles definition into the named context
getAttribute() Returns a named tiles attribute from the current tiles definition
importAttribute() Imports a named attribute in the current tiles definition into the named context.
get() Inserts the named tile into the current tile.
See Also
The Javadoc for more info.
importAttributes()
       

Imports all attributes in the current tiles definition into the named context

void importAttributes()

void importAttributes(String scope)

Parameters
scope
The named context scope to put the attributes into. Possible values are page (velocity-context), request, session, and application.

This method makes it possible to import all attributes, defined in the current tiles definition, into any scope, to be accessed i.e. by other tiles.

Assuming that the tiles config contains the following definition(and ".tilename" is the current tiles definition):

<definition name=".tilename" path="/layout.vm">
    <put name="attr1" value="This is one attribute."/>
    <put name="attr2" value="and this is a another."/>
</definition>

then the following Velocity script:

$tiles.importAttributes()
$attr1
$attr2

produces this output:

This is one attribute
and this is another one

getAttribute()
       

Returns a named tiles attribute from the current tiles definition

String getAttribute(String attributeName)

Parameters
attributeName
The name of the tiles-definition attribute.
Returns
Returns the named tiles attribute from the current tiles definition

This method makes it possible to fetch any attribute defined in the current tiles definition.

Assuming that the tiles config contains the following definition (and ".tilename" is the current tiles definition):

<definition name=".tilename" path="/layout.vm">
    <put name="attr1" value="This is one attribute."/>
    <put name="attr2" value="and this is a another."/>
</definition>

then the following Velocity script:

$tiles.getAttribute("attr1")

produces this output:

This is one attribute

importAttribute()
       

Imports a named attribute in the current tiles definition into the named context.

void importAttribute(String attributeName)

void importAttribute(String attributeName, String scope)

Parameters
attributeName
The name of the tiles-definition attribute.
scope
The named context scope to put the attributes into. Possible values are page (velocity-context), request, session, and application.

This method makes it possible to import a named attribute, defined in the current tiles definition, into any scope, to be accessed i.e. by other tiles.

Assuming that the tiles config contains the following definition(and ".tilename" is the current tiles definition):

<definition name=".tilename" path="/layout.vm">
    <put name="attr1" value="This is one attribute."/>
    <put name="attr2" value="and this is a another."/>
</definition>

then the following Velocity script:

$tiles.importAttribute("attr1")
$attr1

produces this output:

This is one attribute

get()
       

Inserts the named tile into the current tile.

void get(Object attr)

Parameters
attr
The name of the tile to insert.

This method makes it possible to insert a named tile, defined in the current tiles definition, into the velocity template.

Assuming that the tiles config contains the following definition(and ".tilename" is the current tiles definition):

<definition name=".tilename" path="/layout.vm">
    <put name="header" value="/header.vm"/>
</definition>

then the following two Velocity scripts:

<!-- layout.vm -->
<html>
$tiles.header
<body>
    World
</body>
</html>

<!-- header.vm -->
<head>
    <title>Hello</title>
</head>

produce this output:

<html>
<head>
    <title>Hello</title>
</head>
<body>
    World
</body>
</html>


Copyright © 1999-2003, Apache Software Foundation