【发布时间】:2015-07-28 10:04:55
【问题描述】:
我在所有页面中都有一个共同的页眉,除了一些页眉右侧有一些选项的页面。例如,我的标题右侧将有如下选项:块、撰写、编辑,具体取决于页面。是否可以从tiles-config.xml 设置这个headerShowIcons,然后在rhsHeader.jsp 中使用它。
有什么方法可以将一些值从 tiles-config.xml 传递到 rhsHeader.jsp 并基于该值我想显示选项(即阻止、编辑或删除)
示例:如果我想向用户显示 Compose 选项,我只需从 tiles-config.xml 传递值(即 headerShowIcons='compose')并在 JSP 中使用它。如果我想显示块,我将传递 headerShowIcons='block' 将由 rhsHeader.jsp 读取以提供显示块选项。我希望这会更清楚
tiles-config.xml
<definition name="*/*/*/*/*/index" template="/{1}/{2}/xyz/{4}/layouts/layout.jsp">
<put-attribute name="lhsHeader" value="/{1}/{2}/xyz/s/headerWithBack.jsp" />
<put-attribute name="rhsHeader" value="/{1}/{2}/xyz/s/rhsHeader.jsp"/>
<put-attribute name="body" value="/{1}/{2}/xyz/s/myProfile.jsp" />
</definition>
layout.jsp
<!-- What should I add here to meet the requirement -->
<body>
<header>
<div>
<tiles:insertAttribute name="header"/>
<tiles:insertAttribute name="rhsHeader"/>
</div>
</header>
<div>
<tiles:insertAttribute name="body"/>
</div>
</body>
rhsHeader.jsp 是这样的:
<tiles:useAttribute name="headerShowIcons" />
<div class="RHS">
<ul>
<!-- I want to show the options (like- Block,Delete,etc) which will be passed from tiles-config.xml to rhsHeader.jsp (which here I have written it as headerShowIcons )-->
<c:choose>
<c:when test="${headerShowIcons eq 'refine'}">
<li><a href="#" class="refine">Refine</a></li>
</c:when>
<c:when test="${headerShowIcons eq 'block'}">
<li><a href="#" class="block">Block</a></li>
</c:when>
<c:when test="${headerShowIcons eq 'edit'}">
<li><a href="javaScript:void(0);" class="edit">Edit</a></li>
</c:when>
<c:when test="${headerShowIcons eq 'delete'}">
<li><a href="javaScript:void(0);" class="delete">Delete</a></li>
</c:when>
<c:otherwise>
<p>test</p>
</c:otherwise>
</c:choose>
</ul>
【问题讨论】:
标签: xml jsp spring-mvc jstl apache-tiles