亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

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

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

瀏覽:161日期: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必須要要到母版頁【對(duì)的 其實(shí)sitemesh不就像是asp.net中的母版頁么】

增加對(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三级三级看三级 | 欧美做爱毛片 | 久久―日本道色综合久久 | 久久亚洲精品中文字幕三区 | 国产一级在线观看www色 | 美女国产在线观看免费观看 | 欧美a极品极品欧美 | 有码一区 | 久久精品在线免费观看 | 国产美女一区二区 | 欧美日韩高清性色生活片 | 在线成人aa在线看片 | 欧美日韩乱国产 | 亚洲视频精品在线 | 中文字幕成人网 | 国产一区精品 | 欧美综合在线观看 | 亚洲第一页视频 | 亚洲欧美日韩在线不卡中文 | 欧美xxxx色视频在线观看 | 欧美在线不卡 | 一级片aaa| 97精品国产高清在线看入口 | 欧美国产精品不卡在线观看 | 国产三级在线观看免费 | 男人一进一出桶女人视频 | 亚洲精品久久九九热 | 国产成人精品三级 | 狠狠一区| 99久久免费午夜国产精品 | 精品久久久久久中文字幕一区 | 另类亚洲孕妇分娩网址 | 日韩欧美理论片 | 欧做爰xxxⅹ性欧美大 | 午夜一区二区福利视频在线 | 国产高清免费视频 | 香蕉久久一区二区不卡无毒影院 | 久久精品一区二区免费看 |