Skip to Main Content
Jakarta Struts Cookbook
book

Jakarta Struts Cookbook

by Bill Siggelkow
February 2005
Intermediate to advanced content levelIntermediate to advanced
528 pages
12h 53m
English
O'Reilly Media, Inc.
Content preview from Jakarta Struts Cookbook

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Jakarta Struts

Programming Jakarta Struts

Chuck Cavaness
Beginning Spring Framework 2

Beginning Spring Framework 2

Bruce Snyder, Sing Li, Anne Horton, Thomas Van de Velde, Naveen Balani, Christian Dupuis
Java Cookbook

Java Cookbook

Ian F. Darwin
Struts 2 in Action

Struts 2 in Action

J. Scott Stanlick, Chad Michael Davis, Donald J. Brown

Publisher Resources

ISBN: 059600771XSupplemental ContentErrata Page