麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > JSP > 正文

jsp中sitemesh修改tagRule技術分享

2024-09-05 00:23:33
字體:
來源:轉載
供稿:網友

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

jsp,sitemesh,tagRule

可以看到其實可以選擇

/** * 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>

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

弊端

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

增加對應的sitemesh:write標簽

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

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

解決

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

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

在processEnd時直接將對應的元素直接append

最終可以直接輸出

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


注:相關教程知識閱讀請移步到JSP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产成人精品一区二区视频免费 | 蜜桃网站免费 | 久精品久久| 婷婷久久综合九色综合色多多蜜臀 | 久久亚洲成人网 | 精品一区二区6 | 欧美视频在线一区二区三区 | 欧美中文日韩 | av电影手机在线看 | 国产免费久久久久 | 欧美爱爱视频 | 污片视频网站 | 久久国产不卡 | 一级成人免费 | 欧美福利视频一区二区三区 | 91美女福利视频 | 免费黄色一级网站 | 1314成人网 | 亚洲网站免费观看 | 国产精品久久久久网站 | 91 在线观看 | 成人国产精品久久久 | 亚洲一区 国产 | 一级免费视频 | 青青草成人av | 成人做爰s片免费看网站 | 午夜精品久久久久久久96蜜桃 | 深夜免费福利视频 | 妇子乱av一区二区三区 | 国产精品久久久久久一区二区三区 | 日本aaaa片毛片免费观蜜桃 | 日本中文不卡视频 | 黄色毛片前黄 | 99国产精品欲a | 91成人免费看片 | 97香蕉超级碰碰久久免费软件 | 黄色一级视频 | 天天草天天干天天 | 热久久91 | 色骚综合 | 黄色片网站免费在线观看 |