SiteMesh
From OpenSymphony.
Code can be downloaded here.
Overview
Web-page layout and decoration. Aids generating consistent look/feel, navigation and layout scheme. Can include other pages (server-side include). J2EE, but can be used outside as well (PHP, CGI…). Extensible.
Setting up
pom.xml
<dependency>
<groupId>opensymphony</groupId>
<artifactId>sitemesh</artifactId>
<version>2.4.2</version>
</dependency>
web.xml
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<jsp-config>
<taglib>
<taglib-uri>sitemesh-page</taglib-uri>
<taglib-location>/WEB-INF/sitemesh-page.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>sitemesh-decorator</taglib-uri>
<taglib-location>/WEB-INF/sitemesh-decorator.tld</taglib-location>
</taglib>
</jsp-config>
Copy in mentioned files (tld)
decorators.xml
<decorators defaultdir="/decorators">
<decorator name="main" page="main.jsp">
<pattern>*</pattern>
</decorator>
<decorator name="printable" page="printable.jsp"/>
</decorators>
Default logic to determine what decorator to apply, first match:
- Meta decorator tag in page
- Don’t apply a decorator to frame set
- Url with printable=true parameter (If so, use the printable decorator.)
- Does the page specifically request a decorator by the decorator file name?
- Does the page url match a pattern in the decorators.xml file?
Can be overridden.
Decorator example
<%@taglib uri="sitemesh-decorator" prefix="decorator"%>
<decorator:usePageid="myPage"/>
<html>
<head>
<title>SiteMesh main - <decorator:title default="Welcome!"/></title>
<decorator:head/>
</head>
<body>
<h1>SiteMesh main <decorator:title default="Welcome!"/></h1>
<h3><a
href="mailto:<decorator:getProperty property="meta.author"
default="staff@example.com"/>">
<decorator:getProperty property="meta.author"
default="staff@example.com"/>
</a>
</h3>
<hr/>
<decorator:body/>
<p><small> (<a href="?printable=true">printable version</a>)</small></p>
</body>
</html>