sitemesh3.0 自定义标签

来源:互联网 发布:网络赌托算什么犯罪 编辑:程序博客网 时间:2024/06/05 05:48

对于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">&copy; 2016 仙飞 版权所有 </p></div><sitemesh:write property='myfooter'/></body>
只贴了body部分,其他的也不重要;

下面是子页面的引用:

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


如有疑问,可留言,亦可提建议。微笑





1 0
原创粉丝点击