Once SiteMesh has been installed and configured, you can begin writing decorators for your web application.
Decorators are the pages that "decorate" the original, requested page (the page that is handed to the SiteMesh filter from the web container). Most (HTML) decorators are a combination of:
meta tags (keywords, description, author)
First, define what different navigation/layout schemes you need. For example: Do I need a default decorator (a standard one for all pages)? Do I have a special layout for the index page? Is the header needed for my documentation files? Do I need printable version of my website?
Web Application Structure
Here is an example structure of a web application. This is not needed for SiteMesh to work.
Directory containing all decorator files (e.g. main.jsp, printable.jsp).
Directory containing all files to be included into other files (e.g. header.jsp, footer.jsp, copyright.jsp).
Directory containing all images (e.g. background.gif, logo.gif).
Directory containing all .CSS styles (e.g. ie4.css, ns4.css).
Define a stylesheet to use in the entire application and include it using this script.
Use includes in your decorators (e.g. includes/navigation.jsp, includes/style.jsp).
Try not to refer to the absolute root ("/") path. Use <%=request.getContextPath()%>/ instead. This will make life easier when moving your web application under another context path.
Making your decorators compatible with multiple browsers (IE, Mozilla, Opera, ...) will (probably) make your entire application (all decorated pages) compatible.
Be careful when using frames, because decorators may NOT be applied to frames (FrameSetDecoratorMapper).
My First Decorator
Here is an example of a decorator (save it as /decorators/main.jsp):
An explanation of the decorator. This way different people working on the decorator are quickly up to speed.
This is needed for the decorator: tags to work (also needed on all pages that work with inline decorators (page:applyDecorator).
Sets the necessary response headers to let the browser cache the page. Omit this line if your application is real dynamic (changing data).
If the requested page doesn't have a title, the default title is used ("INTRANET").
The status bar gets a message when the page is loading.
The entire body of the requested page has the docBody class. This way the navigation and body do not have to have the same font.
Now open WEB-INF/decorators.xml with your favorite editor and let SiteMesh know there is a decorator (with a mapping):
Now deploy the web application, go to the welcome page, and the main decorator will be applied.
More examples are included with the SiteMesh source distribution, under the src/example-webapp directory. If the examples don't give you enough to go on, take a look at SiteMesh in action, download the petsoar-app at http://www.wiley.com/legacy/compbooks/walnes/.