亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁/技術文章
文章詳情頁

jsp中sitemesh修改tagRule技術分享

瀏覽:111日期:2022-06-07 16:50:14

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

最終可以直接輸出

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

標簽: JSP
相關文章:
主站蜘蛛池模板: 在线看片 在线播放 | 日韩在线视频中文字幕 | 久久www免费人成看片入口 | 日本亚洲欧美国产日韩ay高清 | 日韩一区二区三区精品 | 亚洲精品综合久久 | 国产98在线传媒在线视频 | 久久国产在线视频 | 韩国三级欧美三级国产三级 | 好爽好深好猛好舒服视频上 | 国产精品免费久久久久影院 | 美女一级毛片免费不卡视频 | a免费在线观看 | 国产成综合 | 美国一级毛片oo | 美国一级片免费看 | 久久精品最新免费国产成人 | 国产三级精品美女三级 | 色天天综合久久久久综合片 | 美女国产网站 | 插插插av| 亚洲色图第一页 | 国产极品视频 | 特黄特黄 | 久草一区| 国产成人精品一区二区仙踪林 | 国产午夜精品福利久久 | 国产精品福利午夜在线观看 | 日本精品久久久久中文字幕2 | 六月婷婷精品视频在线观看 | 伊人色综合琪琪久久社区 | 182午夜视频 | 在线观看免费视频片 | 亚洲毛片儿 | 久久久久夜 | 国产一级黄色网 | 亚洲国产一区二区在线 | 亚洲免费在线视频播放 | 亚洲六月婷婷 | 国产成人精品视频免费 | 免费观看一级特黄三大片视频 |