婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > jsp中sitemesh修改tagRule技術分享

jsp中sitemesh修改tagRule技術分享

熱門標簽:外呼系統使用方法 南通通訊外呼系統產品介紹 自繪地圖標注數據 電銷機器人免培訓 潤滑油銷售電銷機器人 海外圖書館地圖標注點 如何看懂地圖標注點 電話機器人需要使用網絡嗎 給地圖標注得傭金

sitemesh默認提供了一些常用的rule

可以看到其實可以選擇

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

用法很簡單使用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 class="mainBody">
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

最終可以直接輸出

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

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

標簽:銅川 樂山 南京 貸款邀約 內江 大連 廣州 黃石

巨人網絡通訊聲明:本文標題《jsp中sitemesh修改tagRule技術分享》,本文關鍵詞  jsp,中,sitemesh,修改,tagRule,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《jsp中sitemesh修改tagRule技術分享》相關的同類信息!
  • 本頁收集關于jsp中sitemesh修改tagRule技術分享的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 惠安县| 洪雅县| 托克逊县| 安乡县| 延长县| 扶余县| 井陉县| 寿光市| 上杭县| 陆丰市| 余江县| 瑞丽市| 泗水县| 嘉兴市| 中西区| 三明市| 沐川县| 灵丘县| 齐河县| 长岭县| 越西县| 牙克石市| 乐平市| 蕉岭县| 寿阳县| 霸州市| 庆安县| 安徽省| 二连浩特市| 西城区| 台中市| 始兴县| 盈江县| 肥城市| 读书| 贵州省| 临泉县| 绵竹市| 如皋市| 山丹县| 七台河市|