国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

jsp中sitemesh修改tagRule技術分享

瀏覽:152日期:2022-06-07 16:50:14

sitemesh默認提供了一些常用的rule

可以看到其實可以選擇

/** * Extracts the contents of any elements that look like * <code>&lt;content tag="foo"&gt;...&lt;/content&gt;</code> and write the contents * to a page property (page.foo). * * <p>This is a cheap and cheerful mechanism for embedding multiple components in a * page that can be used in different places in decorators.</p> * * @author Joe Walnes */public class ContentBlockExtractingRule extends BasicBlockRule<String> { private final ContentProperty propertyToExport; public ContentBlockExtractingRule(ContentProperty propertyToExport) {  this.propertyToExport = propertyToExport; } @Override protected String processStart(Tag tag) throws IOException {  tagProcessorContext.pushBuffer();  return tag.getAttributeValue("tag", false); } @Override protected void processEnd(Tag tag, String tagId) throws IOException {  propertyToExport.getChild(tagId).setValue(tagProcessorContext.currentBufferContents());  tagProcessorContext.popBuffer(); }}

修改ScriptTagRuleBundle處理如下

public class ScriptTagRuleBundle implements TagRuleBundle { @Override public void install(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {  defaultState.addRule("content", new ContentBlockExtractingRule(contentProperty.getChild("page"))); } @Override public void cleanUp(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) { }}

用法很簡單使用content作為tag默認填上tag即可

比如

<content tag="reference"><script type="text/javascript" src="<%=path%>/plugins/select2/js/select2.min.js"></script><script type="text/javascript" src="<%=path%>/plugins/select2/js/i18n/zh-CN.js"></script><script type="text/javascript" src="<%=path%>/plugins/bootstrap-modal/js/bootstrap-modal.js"></script><script type="text/javascript" src="<%=path%>/plugins/bootstrap-modal/js/bootstrap-modalmanager.js"></script></content>

在模板中這樣

<body><sitemesh:write property="body"/><sitemesh:write property="page.reference"/></body>

這樣就可以很簡單的放入到任意位置!!!

弊端

這樣雖然很簡單 但是也存在一些問題 開發如果需要增加新的content必須要要到母版頁【對的 其實sitemesh不就像是asp.net中的母版頁么】

增加對應的sitemesh:write標簽

propertyToExport.getChild(tagId).setValue(tagProcessorContext.currentBufferContents());

并且上述代碼中同樣存在覆蓋的問題 比如多處使用了同樣的tagId

解決

sitemesh似乎沒有提供直接用來拼接多個的tagRule

如果有需求將某塊元素放入到末尾 可以考慮增加tagRule

在processEnd時直接將對應的元素直接append

最終可以直接輸出

以上就是我們給大家整理的本次教程的全部內容,感謝你對的支持。

標簽: JSP
相關文章:
主站蜘蛛池模板: 涩涩网站| 国内精品线在线观看 | 男人的天堂视频在线 | 全部免费国产潢色一级 | 99在线精品免费视频九九视 | 亚洲欧美国产一区二区三区 | a级免费| 国产精品自在自线亚洲 | 欧美成人性色xxxxx视频大 | 久青草免费视频 | 91久久精一区二区三区大全 | 亚洲第一区精品日韩在线播放 | 黄色在线视屏 | 国产日韩欧美视频 | 久久99精品久久久久久青青91 | 黄色毛片在线 | 免费永久观看美女视频网站网址 | 无内丝袜透明在线播放 | 一区在线免费观看 | 亚洲一区二区三区久久久久 | 香蕉久久夜色精品国产2020 | 操12p| 视频日韩 | 91九色精品国产免费 | 中国a级毛片免费 | 成人一级 | 激情宗合| 国产精品日本一区二区在线播放 | 欧美精品亚洲精品日韩专区 | 日本一级爽毛片在线看 | 真人一级一级特黄高清毛片 | 加勒比在线视频 | 国产精品自在线天天看片 | 99九九精品国产高清自在线 | 亚洲国产精品线播放 | 国产男人的天堂 | 精品国产成人a区在线观看 精品国产成人a在线观看 | 免费一级做a爰片久久毛片 免费一级做a爰片性色毛片 | 四虎免费大片aⅴ入口 | 日韩一级性生活片 | 亚洲成人www|