Apache Struts 2 Documentation > Home > Guides > Plugin Guide > SiteMesh |

Apache Struts 2 Documentation
SiteMesh
Edit Page Browse Space Add Page Add News
Added by Patrick Lightbody, last edited by Ted Husted on Sep 11, 2006 (view change)

| About SiteMesh SiteMesh is a web-page layout and decoration framework and web application integration framework to aid in creating large sites consisting of many pages for which a consistent look/feel, navigation and layout scheme is required.

The framework integrates well with SiteMesh "out of the box".

The framework stores all its value stack information as request attributes, meaning that if you wish to display data that is on the stack (or even the ActionContext), you can do so by using the normal tag libraries that come with the framework. That's it!

## ActionContextCleanUp

Under the framework's Architecture, the standard filter-chain optionally starts with the `ActionContextCleanUp` filter, followed by other desired filters. Lastly, the `FilterDispatcher` handles the request, usually passing it on to the ActionMapper. The primary purpose of the ActionContextCleanUp is to provide SiteMesh integration. The clean-up filter tells the dispatcher filter exactly when to remove obsolete objects from the request. Otherwise, the ActionContext may be removed before the decorator attempts to access it.

| Order Matters If ActionContext access is required within the decorators, the ActionContextCleanUp filter must be placed at the beginning of the filter-chain.

| Javadoc: (org.apache.struts.action2.dispatcher.ActionContextCleanUp)
Content pulled from external source. Click here to refresh.
Special filter designed to work with the FilterDispatcher and allow for easier integration with SiteMesh. Normally, ordering your filters to have SiteMesh go first, and then FilterDispatcher go second is perfectly fine. However, sometimes you may wish to access Struts features, including the value stack, from within your SiteMesh decorators. Because FilterDispatcher cleans up the ActionContext, your decorator won't have access to the data you want. By adding this filter, the FilterDispatcher will know to not clean up and instead defer cleanup to this filter. The ordering of the filters should then be: this filter SiteMesh filter FilterDispatcher

## FreeMarker and Velocity Decorators

The framework provides an extension of the SiteMesh PageFilter to assist with integration with Velocity and FreeMarker. Our filters provide the standard variables and Struts Tags that you used to create views in your favorite template language.

### FreeMarker

The FreeMarkerPageFilter extends the SiteMes PageFilter to allow direct access to framework variables such as `$stack` and `$request`.

In the `web.xml`, the VelocityPageFilter should be placed between the `ActionContextCleanUp` and the {FilterDispatcher}}.

| Javadoc: (example.freemarker.filter.chain)
Content pulled from external source. Click here to refresh.
    <filter>
        <filter-name>struts-cleanup</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
    </filter>
    <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>org.apache.struts2.sitemesh.FreeMarkerPageFilter</filter-class>
    </filter>
    <filter>
        <filter-name>struts</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts-cleanup</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
An error occurred: https://svn.apache.org/repos/asf/struts/struts2/trunk/core/src/main/java/org/apache/struts2/sitemesh/FreeMarkerPageFilter.java. The system administrator has been notified.

### Velocity

The VelocityPageFilter extends the SiteMesh PageFilter to allow direct access to framework variables such as `$stack` and `$request`.

In the `web.xml`, the VelocityPageFilter should be placed between the `ActionContextCleanUp` and the {FilterDispatcher}}.