...
- Can use Struts tags in Sitemesh decorator templates
Usage
ActionContextCleanUp
Under the framework's architecture, the standard filter-chain optionally starts with the ActionContextCleanUp
filter (or StrutsPrepareFilter
since 2.1.3), followed by other desired filters. Lastly, the FilterDispatcher
(or StrutsExecuteFilter
) 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.
Warning | ||
---|---|---|
| ||
If ActionContext access is required within the decorators, the ActionContextCleanUp filter must be placed at the beginning of the filter-chain. |
- Sitemesh decorators can be written in FreeMarker as well as Velocity and JSP
Usage
From 2.2+ the new com.opensymphony.sitemesh.webapp.SiteMeshFilter
filter ans Struts org.apache.struts2.dispatcher.ng.listener.StrutsListener
context listener must be added to web.xml
, like:
Code Block | ||||
---|---|---|---|---|
| ||||
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
...
<listener>
<listener-class>org | ||||
Info | ||||
| ||||
Wiki Markup | .apache.struts2.dispatcher. ActionContextCleanUp} | |||
Warning | ||||
| ||||
Since Struts 2.1.3, ActionContextCleanUp and FilterDispatcher are deprecated. Use StrutsPrepareFilter and StrutsExecuteFilter instead.ng.listener.StrutsListener</listener-class>
</listener>
|
FreeMarker and Velocity Decorators
The plugin provides an extension of the SiteMesh PageFilter to assist with integration with Velocity and FreeMarker servlets. Our filters servlets provide the standard variables and Struts Tags that you used to create views in your favorite favourite template language.
FreeMarker
The FreeMarkerPageFilter 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
.
...
title | Javadoc: (org.apache.struts2.sitemesh.FreeMarkerPageFilter) |
---|
...
From 2.2+ the recommended way to use Freemarker with Sitemesh is through the org.apache.struts2.sitemesh.FreemarkerDecoratorServlet
servlet, which can be configured like this in web.xml
:
Code Block | ||||
---|---|---|---|---|
| ||||
<servlet>
<servlet-name>sitemesh-freemarker</servlet-name>
<servlet-class>org.apache.struts2.sitemesh.FreemarkerDecoratorServlet</servlet-class>
<init-param>
<param-name>default_encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>
|
Velocity
...
From 2.2+ the recommended way to use Velocity with Sitemesh is through the
org.apache.struts2.sitemesh.
...
VelocityDecoratorServlet
servlet, which can be configured like this in web.xml
:
Code Block | ||||
---|---|---|---|---|
| ||||
<servlet>
<servlet-name>sitemesh-freemarker</servlet-name>
<servlet-class>org.apache.struts2.sitemesh.VelocityDecoratorServlet</servlet-class>
<init-param>
<param-name>default_encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>
|
Velocity
The VelocityPageFilter extends the SiteMesh PageFilter to allow direct access to framework variables such as $stack
and $request
.
...
Example
Here is an example of how to configure the filter chains in web.xml
:
...