Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

As discussed in Decorating Beyond URL Patterns, SiteMesh out of the box uses sitemesh-default.xml which contains mappers to how decorators are applied.

In some cases you want to go beyond the defaults and use more advanced mappers or even define you own custom mappers.

Creating Your Own sitemesh.xml

To start copy the sitemesh-default.xml file from your SiteMesh jar file into your web applications WEB-INF directory and rename it sitemesh.xml.

Here are the contents of sitemesh-default.xml from sitemesh-2.4.1.jar



Specify Decorator using Query Parameters with PageDecoratorMapper

With this modification, individual pages will be able to specify the decorator to use with a query string parameter. For example, the following url would override the default coffeebreak pattern based decorator and load a Paris themed decorator.

First, add to the sitemesh.xml the PageDecoratorMapper,

The order of the mapper elements determine precedence. A well behaved application should use the following order,

  1. Parameter query = ParameterDecoratorMapper
  2. Page specific using meta tag = PageDecoratorMapper
  3. Pattern = ConfigDecoratorMapper

Keep in mind that the nature of the mapper elements can override the order set by the developer.

For example, a common mistake is to put ConfigDecoratorMapper before PageDecoratorMapper. Because ConfigDecoratorMapper is so general, technically all pages request would cause a decorator to be loaded and as such the PageDecoratorMapper never gets loaded. Even in the case of an exclude in decorators.xml, the match is to not apply a decorator and again PageDecoratorMapper is never loaded.

  • No labels