色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

jsp中sitemesh修改tagRule技術(shù)分享

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

sitemesh默認(rèn)提供了一些常用的rule

可以看到其實(shí)可以選擇

/** * 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) { }}

用法很簡(jiǎn)單使用content作為tag默認(rèn)填上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>

這樣就可以很簡(jiǎn)單的放入到任意位置!!!

弊端

這樣雖然很簡(jiǎn)單 但是也存在一些問題 開發(fā)如果需要增加新的content必須要要到母版頁(yè)【對(duì)的 其實(shí)sitemesh不就像是asp.net中的母版頁(yè)么】

增加對(duì)應(yīng)的sitemesh:write標(biāo)簽

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

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

解決

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

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

在processEnd時(shí)直接將對(duì)應(yīng)的元素直接append

最終可以直接輸出

以上就是我們給大家整理的本次教程的全部?jī)?nèi)容,感謝你對(duì)的支持。

標(biāo)簽: JSP
相關(guān)文章:
主站蜘蛛池模板: 亚洲日本一区二区三区高清在线 | 免费观看a视频 | 精品久久久视频 | 免费aⅴ在线 | 亚洲专区视频 | 色婷婷激婷婷深爱五月老司机 | 日韩毛片免费视频一级特黄 | 超级碰碰碰视频视频在线视频 | 久久精品视频一区 | 欧美一区a | 美国三级毛片 | 国内精品线在线观看 | 亚洲国产精品成人久久 | 青草欧美 | 无毛片| 美女视频黄.免费网址 | 欧美第五页 | 国产做爰一区二区 | 中国a级淫片免费播放 | 福利视频专区 | 亚洲国产午夜看片 | 国产91一区二区在线播放不卡 | 永久免费91桃色福利 | 欧美日韩人成在线观看 | 无码免费一区二区三区免费播放 | 正在播真实出轨炮对白 | 国产亚洲欧美ai在线看片 | 日本一区三区二区三区四区 | 久久99国产亚洲精品观看 | 亚洲精品中文一区不卡 | 日韩欧美在线综合网高清 | 亚洲成年网 | 欧美一级片手机在线观看 | 国产亚洲精品国产一区 | 日本三级香港三级三级人!妇久 | 久久精品人人爽人人爽快 | 成人久久久久 | 国产高清美女一级a毛片久久 | 波多野结衣一区二区在线 | 亚洲精品无码专区在线播放 | 99在线小视频 |