del.icio.us Digg DZone Reddit StumbleUpon
Adding Modules to a Struts/Tiles Application - Willie Wheeler
« Previous | 1 | 2 | 3

Modify tiles-defs.xml and Related Files

This is somewhat involved (not too bad, but more so than the other major steps), so I'll organize this a bit.

Step 1. First, you'll need to break up the tiles-defs.xml into multiple files, in the same way you did with the struts-config.xml file. I broke mine into tiles-defs.xml (default module), tiles-defs-articles.xml, and tiles-defs-software.xml. In slightly more detail, this means that definitions that are specific to a given module go in that module's tiles-defs-xxx.xml file. Shared definitions just go in the default module's tiles-defs.xml file, where they can be imported by other modules in a way to be described in just a bit.

IMPORTANT: There's an important disanalogy between the way one modularizes the Struts config and the way one modularizes the Tiles config. With the Struts config, the action paths are understood to be relative to the module, which is consistent with the standard understanding of what a module is. With the Tiles config, on the other hand, the paths to the JSPs are not relativized to the module directories. Not sure why this is, and to me (and apparently others) this seems to break the "module" semantics, but that's the way it works. The punchline is this: just move the Tiles defs to the right file; don't modify the JSP paths.

Step 2. Now go into your various struts-config.xml files, and modify the TilesPlugin definition in each one. There are two changes you'll need:

Step 2.1. Change

<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"/>

to something along the lines

<set-property property="definitions-config"
     value="/WEB-INF/tiles-defs.xml,/WEB-INF/tiles-defs-articles.xml"/>

The list of Tiles definition files you include depends on whether your module's Tiles config references definitions contained in another config file. The most common case of this would be that your tiles-defs.xml config contains a bunch of shared layout definitions, and your non-default modules want to use them. Anyway, you need to include all directly and indirectly referenced files in the comma-separated list.

(In the special case of the default Struts config file, you probably won't need anything other than /WEB-INF/tiles-defs.xml.)

Step 2.2. Add the following to the TilesPlugin definition:

<set-property property="moduleAware" value="true"/>

This tells Struts to create a separate Tiles factory for each module, which you want since you're modularizing the Tiles config files. IMPORTANT: Don't forget to add this to the default module as well!

Step 3. Cross your fingers and fire it up.

That's how to do it. Good luck!

Social bookmarks: del.icio.us Digg DZone Reddit StumbleUpon
« Previous | 1 | 2 | 3

Comments (0)

No comments have yet been posted.

Post a comment

Your name:
Your e-mail address (won't be displayed):
Your web site (optional):
example: www.xyz.com
Your comment:
Preview:
By You
Please help us reduce comment spam:
Spring in Practice
My brother and I are writing Spring in Practice for Manning!

What's New?

2008-12-14 - We've just submitted a few more chapters of the book for review, so we're about halfway done.
2008-10-20 - I've added a new mailing list feature to the site. Sign up to receive e-mail updates about new articles.
2008-09-30 - We've released chapter 4 (User registration) and chapter 5 (Authentication) of Spring in Practice.
2008-09-11 - By popular demand, I've added an RSS feed to the site.
Home | Consulting | Tech Articles | Mailing List | Contact | Spring Blog
Copyright © 2008 Wheeler Software, LLC.