国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-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久热在线精品视频播放6 | a男人的天堂久久a毛片 | 日韩中文字幕精品 | 欧美成人视屏 | 欧美一区二区在线观看免费网站 | 欧美日韩一区二区三区四区在线观看 | 538在线视频二三区视视频 | 在线亚洲欧美日韩 | 国产成人啪精品视频免费网 | 99精品免费久久久久久久久日本 | 一级片免费观看视频 | a级毛片免费高清视频 | 亚洲人成人毛片无遮挡 | 97精品久久久久中文字幕 | 亚洲一区 欧美 | 久久精品国产亚洲综合色 | 国产成人综合日韩精品无 | 亚洲欧洲一级 | 99精品在线观看视频 | 国产一级二级三级毛片 | 国产精品合集一区二区 | 一级片在线观看视频 | 国产一区二区三区日韩 | 日韩毛片免费线上观看 | 九九视频免费在线观看 | 免费永久国产在线视频 | 国产色啪午夜免费视频 | 国产精品一国产精品免费 | 女人张开腿让男人捅的视频 | 亚洲黄区 | 欧美成人看片黄a免费看 | 亚洲国产精品成人午夜在线观看 | 成人午夜毛片在线看 | 亚洲精品视频网 | 三级黄色网址 | 综合在线播放 | 久久精品视频在线观看榴莲视频 | 久久99久久精品免费思思6 | 欧美成人xxx | 亚洲天码中文字幕第一页 | 欧美一级特黄aa大片视频 |