JavaScud | Forum | JIRA | Blog |
  Dashboard > WebWork2文档中文化计划 > ... > 3rd Party Integration > SiteMesh
  WebWork2文档中文化计划 Log In View a printable version of the current page.  
  SiteMesh
Added by scud, last edited by Jeff Wang on May 22, 2006  (view change)
Labels: 
(None)

Overview

SiteMesh是一个Web页面布局修饰框架, 用于构建包含大量页面, 需要一致的外观样式(look/fell), 导航和布局机制的大型网站.

在WebWork中集成SiteMesh相当容易: 实际上什么也不用做. WebWork把全部值栈数据都保存在请求attribute中, 这意味着如果想显示值栈(或ActionContext)中的数据, 只需使用WebWork附带的标准标签库, 就这么简单!

ActionContextCleanUp

在WebWork的架构中, 标准的过滤器链(filter-chain)一般以 ActionContextCleanUp 开始, 后面跟着其他需要的过滤器. 最后, 由 FilterDispatcher 处理请求, 通常是将请求传递给ActionMapper. ActionContextCleanUp 的首要用途是为集成SiteMesh服务的. 他会通知FilterDispatcher在正确的时间清除请求. 否则, ActionContext将在SiteMesh修饰器访问数据之前被清除.

警告
如果需要在修饰器中访问ActionContext, ActionContextCleanUp 过滤器必须放在过滤器链的起点.

更多信息参见ActionContextCleanUp的JavaDoc文档:

该过滤器用来与FilterDispatcher协同工作以便于集成SiteMesh. 通常, 排列过滤器并保证SiteMesh排在第一位, 而让FilterDispatcher排在第二位看起来是最佳方案. 然而, 你可能希望在SiteMesh修饰器中使用WebWork的特性, 包括value stack, 但由于FilterDispatcher将清除ActionContext, 因此修饰器就访问不到想要的数据了.

通过添加本过滤器, FilterDispatcher会知道先不执行清除而是将清除推迟到本过滤器中执行, 修改后的顺序如下:

  • 本过滤器
  • SiteMesh
  • FilterDispatcher

(摘自snippet:id=description|javadoc=true|url=com.opensymphony.webwork.dispatcher.ActionContextCleanUp)

Velocity and FreeMarker Decorators

WebWork提供了SiteMesh的PageFilter的一个扩展版本的过滤器用于协助与VelocityFreeMarker的集成. 强烈推荐使用这个过滤器来取代SiteMesh提供的过滤器, 因为当你使用自己喜欢的模版语言创建视图时, 也能够使用标准的变量和标签.

Velocity

如果你要使用Velocity作为SiteMesh修饰器, 推荐使用VelocityPageFilter. 这是SiteMesh的PageFilter的一个扩展版本, 应该定义在web.xml中, 位于 ActionContextCleanUpFilterDispatcher 之间. 这样Velocity修饰器就可以使用$stack和$request来访问WebWork的变量.

Content pulled from external source. Click here to refresh.
<filter>
    <filter-name>webwork-cleanup</filter-name>
    <filter-class>com.opensymphony.webwork.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>com.opensymphony.webwork.sitemesh.VelocityPageFilter</filter-class>
</filter>
<filter>
    <filter-name>webwork</filter-name>
    <filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>
</filter>

<filter-mapping>
    <filter-name>webwork-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>webwork</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

FreeMarker

如果你要使用FreeMarker作为SiteMesh修饰器, 推荐使用FreeMarkerPageFilter. 这是SiteMesh的PageFilter的一个扩展版本, 应该定义在web.xml中, 位于 ActionContextCleanUpFilterDispatcher 之间. 这样FreeMarker修饰器就可以使用${stack}和${request}.来访问WebWork的变量.

Content pulled from external source. Click here to refresh.
<filter>
    <filter-name>webwork-cleanup</filter-name>
    <filter-class>com.opensymphony.webwork.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>com.opensymphony.webwork.sitemesh.FreeMarkerPageFilter</filter-class>
</filter>
<filter>
    <filter-name>webwork</filter-name>
    <filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>
</filter>

<filter-mapping>
    <filter-name>webwork-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>webwork</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
Site running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators