The open-source SiteMesh project provides a web-page layout and decoration framework to achieve a consistent look and feel across multiple web applications.
The new sitemesh.org wiki hosts some tutorials and information. More complete documentation on SiteMesh 2 is available through the Wayback Machine, including the very useful installation and configuration, building decorators, andtag reference documents. Source code is available through Github.
For a more detailed look at SiteMesh, you can review a presentation given by Mike Cannon-Brookes for The Server Side Symposium. It provides a nice overview of what is SiteMesh, how it works and some advanced techniques.
SiteMesh Cheat Sheet
Need to create or tweak a decorator? Look in your skeleton webapp at:
This file contains mappings between URL patterns and decorators. For example:
<decorators> <excludes> <pattern>/error.jsp</pattern> <pattern>/fund-list.json*</pattern> </excludes> <decorator name="default" webapp="/decorators" page="/decorators/1/financial.jsp"> <pattern>/*</pattern> </decorator> </decorators>
maps all requests to the "default" decorator by default, except for
SiteMesh seems to require a default /* pattern. If you need to restrict SiteMesh to one specific path, it may be easier to handle this by changing filter mapping in web.xml. Remember to reload your webapp after making changes to decorators.xml as SiteMesh won't reliably pick up changes to exclusion patterns on the fly.
The decorator JSPs themselves are in the
web application. For example:
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title><decorator:title /></title> <%@ include file="/includes/head-elements.jsp" %> <decorator:head /> </head> <body> <div id="tdr_login"> <!-- Start page controls --> <span class="tdr_login_content"> </span> <!-- End page controls --> </div> ...
As you can see the decorators are pretty basic JSP, with the exception of the SiteMesh tag libraries. See the resources above for more information if/when you get into trouble. Good luck!