14.3. Displaying Tiles Using a Struts Forward
Problem
You don't like having to write and maintain minimal JSP pages that insert a Tiles definition.
Solution
Use action forwards in your
struts-config.xml file
that specify the definition name for the path
attribute on the forward element. The
TilesRequestProcessor, deployed behind the scenes
by the TilePlugin, will forward to the definition
as if it were inserted by a JSP.
Assuming Tiles definitions are in your
tiles-defs.xml file named
.someTilesDef and
.anotherTilesDef, you can create actions such as
the following in your struts-config.xml file:
<action path="/doStartPage"
forward=".someTilesDef"/>
<action path="/doPageOne"
type="com.foo.SomeAction">
<forward name="success" path=".anotherTilesDef"/>
</action>Discussion
If you've read over the first couple of Tiles
recipes, you'll notice that once a definition is
created, its trivial to write JSP code to render the page. Tiles uses
a custom request processor to eliminate the need for these trivial
pages. The TilesPlugin installs the
TilesRequestProcessor when the plug-in
initializes. The
TilesRequestProcessor
provides special handling that allows you to use a Tiles definition
as the target path for a Struts forward. When the
TileRequestProcessor processes the forward, if the forward path matches a Tiles definition name, it loads the definition, creates and initializes the Tile's context attributes, and inserts the corresponding definition. If the path doesn't match a definition, the ...