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

Modify struts-config.xml and Related Files

Basically, all that you need to do here is separate out the various actions into different config files. In my case I needed three config files: struts-config.xml for the default module (home page, About Me, etc.), struts-config-articles.xml for the articles module, and struts-config-software.xml for the software module. Once you separate the files, make sure that each action in your app appears in the correct module config file.

Assuming that you are using Tiles, each struts-config-xxx.xml should contain a TilesPlugin definition. For now point them all to the same tiles-defs.xml file since we'll want to verify that your Struts modularization works before moving onto the Tiles modularization.

Modify JSPs

The first thing to note is that for each module, you will need a corresponding folder in your web directory, and the folder names must be the same as the module names. There may be ways to change the names, but if so, I'm not aware of them. Anyway, the resources corresponding to a given module (such as the JSPs) go in the module folders.

In general, you will need to modify links and images to point to modularized versions of the same. This is somewhere it's nice to use the Struts HTML taglib. Let's look at links first. Continuing with the example of the present web site, I had to change the links

<html:link page="/home.do">Home</html:link>

and

<html:link page="/articles/index.do">Articles</html:link>

to

<html:link module="" action="/home.do">Home</html:link>

and

<html:link module="/articles" action="/index.do">Articles</html:link>

The module attribute is optional unless you need to link to a module that's different than the linking module. When linking to a separate module, use the empty string for the default module, and use /moduleName for other modules, as shown above. If you specify a module explicitly, use the action attribute; otherwise, use the page attribute.

Images are similar to links. Use the module, action, and page attributes in exactly the same way you do with links.

Incidentally, if you have a big site, you will have lots of links and images to update. This might be an argument for using modules from the start, even if you begin with only a single default module.

In addition to links and images, check your CSS, JavaScript, Flash, etc. references. Some of these are probably broken.

Build Process

Not too much to worry about here; just make sure that you include your new Struts config files in your WEB-INF directory so that the ActionServlet can find them. Don't forget tiles-defs.xml and your TLDs.

At this point you should deploy your web app and try things out. The main thing to check is that the links, images, CSS, etc. all resolve correctly. If your app has more than a few pages, there are bound to be broken links. The main problems will probably be things like not having placed slashes in your modules/pages/actions, not including the module attribute for links that take the user from one module to another, etc. If you get stuck on something, see the HTML Taglib API Reference for more information.

Once you are satisfied that your app is working correctly, it's time to modularize the tiles-defs.xml file.

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

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 Annotations RefCard
Check out the new DZone Spring Annotations Refcard by Craig Walls!

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.