您的位置:首页 > 其它

sitemesh3.0 自定义标签

2015-12-22 10:54 316 查看
对于sitemesh3,官方只给出了<title><head><body> 三个标签,但是对于一些特殊的需求是远远不能满足的,好了,不废话了,进入正题:

本文章是基于java类来配置的,先建好sitemesh的配置类SiteMeshFilter ,如下:

public class SiteMeshFilter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
//customer decorator
builder.addTagRuleBundle(new CustomTagRuleBundle());
}
}
接下来是CustomTagRuleBundle,如下:

public class CustomTagRuleBundle implements TagRuleBundle {

@Override
public void install(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {
defaultState.addRule("myfooter", new ExportTagToContentRule(siteMeshContext, contentProperty.getChild("myfooter"), false));
}

@Override
public void cleanUp(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {

}
}
到此为止,就可以了接下里就是解释,

“myfooter” 是我自定义的标签名字,如果需要多个,则只需要在install里面多添加一条addRule;

下面是母页面的引用:

<body>
<sitemesh:write property='body'/>
<div class="footer">
<p align="center">© 2016 仙飞 版权所有 </p>
</div>
<sitemesh:write property='myfooter'/>
</body>
只贴了body部分,其他的也不重要;

下面是子页面的引用:

<body>
<myfooter>
自定义页脚
</myfooter>
</body>


如有疑问,可留言,亦可提建议。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: