av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

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

瀏覽:128日期: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) { }}

用法很簡單使用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>

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

弊端

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

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

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

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

解決

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

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

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

最終可以直接輸出

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

標(biāo)簽: JSP
相關(guān)文章:
主站蜘蛛池模板: 日韩理论电影在线观看 | 91免费看片神器 | 久久91精品国产一区二区三区 | 久久www免费视频 | 五十女人一级毛片 | 久久久久久久久久久国产 | 天天操夜夜操 | 久久免费精品 | 欧美1—12sexvideos | 97在线观看| 国产99免费视频 | 精品1区2区| 婷婷久久综合 | 亚洲国产精品久久久久 | 色综合欧美 | 国产激情在线看 | 欧美一区二区三区久久精品 | 91亚洲国产 | 在线视频成人 | 国产精品久久九九 | 国产超碰人人爽人人做人人爱 | 亚洲网站在线观看 | 一级黄色录像毛片 | 毛片区| 亚洲欧美在线观看视频 | 国产久 | 精品国产第一区二区三区 | 999精品视频| www.99re| 国产精品视频久久久久 | 欧美综合视频在线 | 午夜国产 | 毛片区| 91在线观看| 另类一区 | 黑人性hd | 瑟瑟激情 | 在线观看av网站永久 | 日本不卡一区 | 午夜av一区二区 | 怡红院怡春院一级毛片 |