亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

jsp中sitemesh修改tagRule技術分享

瀏覽:137日期: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
相關文章:
主站蜘蛛池模板: 亚洲乱码一二三四区国产 | 香蕉视频首页 | 欧美亚洲视频一区 | 国内精品久久久久香蕉 | 毛片黄片一级片 | 国产成人综合视频 | 大片免免费观看视频播放网站 | 制服丝袜在线播放 | 一级毛片视频免费 | 精品一区二区三区视频在线观看免 | 国产福利视频奶水在线 | 国产cdts | 国产午夜亚洲精品一级在线 | 日本一区精品 | 亚洲欧美久久久久久久久久爽网站 | 污污网站免费在线观看 | 欧美一级刺激毛片 | 欧美日韩亚洲区久久综合 | 我们不能是朋友未删减版在线看 | 两性毛片| 国产精品一区二区综合 | 亚洲综合资源 | 男女草 | 亚洲国产成人精品久久 | 亚洲精品国产拍拍拍拍拍 | 成人日韩视频 | 欧美一区二区三区东南亚 | 国产区免费在线观看 | 成人午夜精品久久不卡 | 免费大黄网站在线看 | 五月婷婷俺也去开心 | 国产成人精品曰本亚洲77美色 | 黄一级片 | 欧美日韩一区二区中文字幕视频 | 国产亚洲综合成人91精品 | 三级毛片三级毛片 | 你操综合| 日韩精品一区二区三区国语自制 | 久久国产成人精品麻豆 | 全免费观看a级毛片 | 黄色网址免费在线播放 |