濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > jsp中sitemesh修改tagRule技術(shù)分享

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

熱門標(biāo)簽:外呼系統(tǒng)使用方法 南通通訊外呼系統(tǒng)產(chǎn)品介紹 自繪地圖標(biāo)注數(shù)據(jù) 電銷機(jī)器人免培訓(xùn) 潤(rùn)滑油銷售電銷機(jī)器人 海外圖書(shū)館地圖標(biāo)注點(diǎn) 如何看懂地圖標(biāo)注點(diǎn) 電話機(jī)器人需要使用網(wǎng)絡(luò)嗎 給地圖標(biāo)注得傭金

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

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

/**
 * Extracts the contents of any elements that look like
 * code>lt;content tag='foo'gt;...lt;/contentgt;/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 BasicBlockRuleString> {
 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 class="mainBody">
sitemesh:write property='body'/>
sitemesh:write property='page.reference'/>
/body>

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

弊端

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

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

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

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

解決

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

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

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

最終可以直接輸出

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

您可能感興趣的文章:
  • Java SiteMesh新手學(xué)習(xí)教程代碼案例
  • 如何解決SpringBoot2.x版本對(duì)Velocity模板不支持的方案
  • SpringBoot與velocity的結(jié)合的示例代碼
  • JAVA velocity模板引擎使用實(shí)例
  • html文件中jquery與velocity變量中的$沖突的解決方法
  • velocity顯示List與Map的方法詳細(xì)解析
  • Velocity基本語(yǔ)法介紹
  • SiteMesh如何結(jié)合Freemarker及velocity使用

標(biāo)簽:銅川 樂(lè)山 南京 貸款邀約 內(nèi)江 大連 廣州 黃石

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《jsp中sitemesh修改tagRule技術(shù)分享》,本文關(guān)鍵詞  jsp,中,sitemesh,修改,tagRule,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《jsp中sitemesh修改tagRule技術(shù)分享》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于jsp中sitemesh修改tagRule技術(shù)分享的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    涟水县| 郑州市| 垣曲县| 商河县| 潜山县| 阳山县| 上杭县| 丰镇市| 都江堰市| 三门峡市| 丽水市| 太原市| 仪陇县| 四平市| 红安县| 兰坪| 满城县| 鄱阳县| 八宿县| 辰溪县| 宜丰县| 洪泽县| 青川县| 三江| 连江县| 闽清县| 临泉县| 上犹县| 池州市| 肇东市| 沁水县| 民乐县| 洪江市| 阜新市| 澎湖县| 安丘市| 巍山| 广德县| 蒙山县| 清徐县| 保康县|