国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

jsp中sitemesh修改tagRule技術分享

瀏覽:100日期: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
相關文章:
主站蜘蛛池模板: 国产精品自拍合集 | 国产精品嘿咻嘿咻在线播放 | 精品精品国产自在久久高清 | 免费a黄色 | 亚洲高清一区二区三区 | 国产精品a人片在线观看 | 六月丁香久久丫 | 亚洲人成网7777777国产 | 久久观看午夜精品 | 亚洲欧洲日产国产 最新 | 国产一区二区三区在线看 | 99热精品在线免费观看 | 久久国产成人精品麻豆 | 一级欧美一级日韩毛片99 | 国产99久久久久久免费看 | 欧美亚洲国产成人高清在线 | 国产免费一区二区三区在线 | 亚洲gogo人体大胆西西安徽 | 看色网站 | 国内精品久久久久影院网站 | 久久精品一区 | 一级毛片免费完整视频 | 三级毛片网 | 永久免费毛片手机版在线看 | 国产自在自线午夜精品视频 | 黄色成人在线 | 亚洲国内 | 国产欧美久久久精品影院 | 乱人伦中文字幕视频 | 欧美成人久久 | 8000av在线| 日韩欧美国产高清在线观看 | 国产最新网站 | 久9这里精品免费视频 | 久草免费福利视频 | 窝窝人体色 | 有码视频在线观看 | 日韩中文字幕免费观看 | 久草在线观看资源 | 自拍偷拍视频在线观看 | 久久国产精品无码网站 |