ITPub博客

首页 > 应用开发 > IT综合 > Velocity and FreeMarker Decorators

Velocity and FreeMarker Decorators

原创 IT综合 作者:okone96 时间:2007-03-20 11:54:03 0 删除 编辑

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

Velocity

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

Content pulled from external source. Click here to refresh.

    webwork-cleanup
    com.opensymphony.webwork.dispatcher.ActionContextCleanUp


    sitemesh
    com.opensymphony.webwork.sitemesh.VelocityPageFilter


    webwork
    com.opensymphony.webwork.dispatcher.FilterDispatcher



    webwork-cleanup
    /*


    sitemesh
    /*


    webwork
    /*

FreeMarker

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

Content pulled from external source. Click here to refresh.

    webwork-cleanup
    com.opensymphony.webwork.dispatcher.ActionContextCleanUp


    sitemesh
    com.opensymphony.webwork.sitemesh.FreeMarkerPageFilter


    webwork
    com.opensymphony.webwork.dispatcher.FilterDispatcher



    webwork-cleanup
    /*


    sitemesh
    /*


    webwork
    /*
[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/750220/viewspace-905947/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: sitemesh简化页面
下一篇: FreeMarker概述
请登录后发表评论 登录
全部评论
  • 博文量
    83
  • 访问量
    198460