jsp中sitemesh修改tagRule技術分享
sitemesh默認提供了一些常用的rule
可以看到其實可以選擇
/**
* Extracts the contents of any elements that look like
* <code><content tag='foo'>...</content></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默認填上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>
這樣就可以很簡單的放入到任意位置!??!
弊端
這樣雖然很簡單 但是也存在一些問題 開發(fā)如果需要增加新的content必須要要到母版頁【對的 其實sitemesh不就像是asp.net中的母版頁么】
增加對應的sitemesh:write標簽
propertyToExport.getChild(tagId).setValue(tagProcessorContext.currentBufferContents());
并且上述代碼中同樣存在覆蓋的問題 比如多處使用了同樣的tagId
解決
sitemesh似乎沒有提供直接用來拼接多個的tagRule
如果有需求將某塊元素放入到末尾 可以考慮增加tagRule
在processEnd時直接將對應的元素直接append
最終可以直接輸出
以上就是我們給大家整理的本次教程的全部內容,感謝你對我們的支持。
上一篇:秒殺系統(tǒng)Web層設計的實現(xiàn)方法
欄 目:JSP編程
本文標題:jsp中sitemesh修改tagRule技術分享
本文地址:http://www.jygsgssxh.com/a1/JSPbiancheng/11438.html
您可能感興趣的文章
- 01-11在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法
- 01-11jsp文件下載功能實現(xiàn)代碼
- 01-11JSP頁面跳轉方法大全
- 01-11jsp 使用request為頁面添加靜態(tài)數(shù)據(jù)的實例
- 01-11JSP servlet實現(xiàn)文件上傳下載和刪除
- 01-11SpringMail使用過程中的報錯解決辦法
- 01-11JSP狀態(tài)管理的簡單介紹
- 01-11jsp+servlet實現(xiàn)文件上傳與下載功能
- 01-11JSP的setProperty的使用方法
- 01-11Jsp+Servlet實現(xiàn)文件上傳下載 文件上傳(一)


閱讀排行
本欄相關
- 01-11web下載文件和跳轉的方法
- 01-11Spring注入Date類型的三種方法總結
- 01-11在JSP中使用formatNumber控制要顯示的小
- 01-11Properties 持久的屬性集的實例詳解
- 01-11EJB3.0部署消息驅動Bean拋javax.naming.Na
- 01-11jsp文件下載功能實現(xiàn)代碼
- 01-11JSP頁面跳轉方法大全
- 01-11詳解Spring的核心機制依賴注入
- 01-11jsp 使用request為頁面添加靜態(tài)數(shù)據(jù)的實
- 01-11Spring獲取ApplicationContext對象工具類的
隨機閱讀
- 04-02jquery與jsp,用jquery
- 01-10delphi制作wav文件的方法
- 01-11ajax實現(xiàn)頁面的局部加載
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10C#中split用法實例總結
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-10SublimeText編譯C開發(fā)環(huán)境設置
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 08-05織夢dedecms什么時候用欄目交叉功能?


