国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

jsp中sitemesh修改tagRule技術分享

2020-07-26 23:16:09
字體:
來源:轉載
供稿:網友

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

可以看到其實可以選擇

/** * 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默認填上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

最終可以直接輸出

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 惠州市| 遵化市| 林芝县| 武穴市| 潮州市| 嘉祥县| 丹凤县| 徐汇区| 济阳县| 衡阳县| 威远县| 桂林市| 新乡县| 偏关县| 政和县| 巴林右旗| 望江县| 新营市| 宜昌市| 阿拉善盟| 祁连县| 临安市| 鲁甸县| 克什克腾旗| 奉节县| 乌鲁木齐市| 阜阳市| 山东省| 德化县| 沁阳市| 盱眙县| 镶黄旗| 永寿县| 喜德县| 孝感市| 梁河县| 板桥市| 克东县| 日照市| 土默特右旗| 灌阳县|