`
guoyiqi
  • 浏览: 964393 次
社区版块
存档分类
最新评论

SiteMesh3配置

 
阅读更多

SiteMesh3 支持两种主要的配置: XML 和 Java,甚至两者可以共用。

 

XML Java
  • 容易上手
  • 配置更改时可以自动重载
  • 不需要懂得java编程 
  • 更灵活的制定 
  • 不需要多余的配置文件
  • 可以使用JRuby, Groovy, Scala等语言配置

 

 

 

基于xml的配置

配置文件需放置于/WEB-INF/sitemesh3.xml ,如

<sitemesh>
  <mapping path="/*" decorator="/decorator.html"/>
  <mapping path="/admin/*" decorator="/admin-decorator.html"/>
</sitemesh>

 

 

 

基于java的配置

必须编写一个过滤器,继承org.sitemesh.config.ConfigurableSiteMeshFilter 且重载applyCustomConfiguration方法,如

public class MySiteMeshFilter extends ConfigurableSiteMeshFilter {
  @Override
  protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
    builder.addDecoratorPath("/*", "/decorator.html")
           .addDecoratorPath("/admin/*", "/admin/decorator.html");
  }
}

 

 

如果xml和java两个配置方法共用,sitemesh3在调用applyCustomConfiguration()方法前会先加载xml的配置。

 

 

配置渲染

  • 给所有路径配置一个默认的渲染
  • 给特殊的路径配置一个渲染
  • 给某个路径配置多个渲染,一个渲染依赖于前面的渲染
  • 排除某个路径

xml

<sitemesh>

  <!-- 配置默认的渲染器. 将应用于所有路径. -->
  <mapping decorator="/default-decorator.html"/>

  <!-- 配置特定路径的渲染器. -->
  <mapping path="/admin/*" decorator="/another-decorator.html"/>
  <mapping path="/*.special.jsp" decorator="/special-decorator.html"/>

  <!-- 配置多个渲染器. -->
  <mapping>
    <path>/articles/*</path>
    <decorator>/decorators/article.html</decorator>
    <decorator>/decorators/two-page-layout.html</decorator>
    <decorator>/decorators/common.html</decorator>
  </mapping>

  <!-- 不被渲染的路径. -->
  <mapping path="/javadoc/*" exclue="true"/>
  <mapping path="/brochures/*" exclue="true"/>

</sitemesh>

 java

public class MySiteMeshFilter extends ConfigurableSiteMeshFilter {
  @Override
  protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
            // 配置默认的渲染器. 将应用于所有路径.
    builder.addDecoratorPath("/*", "/default-decorator.html")
           // 配置特定路径的渲染器.
           .addDecoratorPath("/admin/*", "/another-decorator.html")
           .addDecoratorPath("/*.special.jsp", "/special-decorator.html")
           // 配置多个渲染器.
           .addDecoratorPaths("/articles/*", "/decorators/article.html", 
                                             "/decoratos/two-page-layout.html", 
                                             "/decorators/common.html")
           // 不被渲染的路径.
           .addExcludedPath("/javadoc/*")
           .addExcludedPath("/brochures/*");
  }
}

 

对于大多数情况,上面的配置就足够使用了。还有更高级的应用,如配置MIME类型,在页面里嵌入tag标签等。

分享到:
评论
5 楼 Gozs_cs_dn 2015-04-18  
请问下博主, 怎样将sitemesh3.xsd绑定 sitemesh3.xml 中进行验证呢
4 楼 guoyiqi 2012-05-02  
hquxiezk 写道
配置多个渲染器用途是什么?

便于分模块管理
3 楼 hquxiezk 2012-04-26  
配置多个渲染器用途是什么?
2 楼 zhouxuejo 2012-03-07  
挺好的。装饰页面标签是怎么加的?
1 楼 dalianfox 2011-11-11  
 
不错,对我有帮助

相关推荐

Global site tag (gtag.js) - Google Analytics