Wednesday, 12 September 2012

Quick Introduction to SiteMesh Concepts

Sitemesh is a small framework facilitating the development of harmonious layouts of web pages across web applications. Instead of maintaining look-and-feel code in each page, this code is grouped in templates. When a page is rendered, its content is extracted and wrapped into a template to generate the final page (decoration).

Sitemesh is integrated with the Servlet technology via filters. Decorators (i.e. templates) are JSP files declared in a WEB-INF/decorators.xml file. These decorators rely on a specific JSP tag library:
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
        prefix="deco" %>
These tags are used in the templates to extract the content of the page to be decorated. For example:
  • <deco:body /> - Extracts the body content of the page to decorate
  • <deco:head /> - Extracts the head section of the page to decorate
  • ...
Sitemesh is configured with the WEB-INF/sitemesh.xml file. This is where the page parser and mappers to decorators are defined. Sitemesh comes with a set of decorator mappers (localization, browser compatibility...) to solve common requirements.

For more details about Sitemesh, see here.