2015-07-28 110 views
1

我在所有頁面中都有一個共同的標題,除了某些頁面,其中有一些選項的標題的右側。例如,我的標題的右側將具有以下選項:塊,撰寫,編輯取決於頁面。可以從tiles-config.xml中設置此headerShowIcons,然後在rhsHeader.jsp中使用它。Apache Tiles 2.2.2將tiles-config.xml傳遞給JSP

有沒有什麼辦法讓我可以通過從瓷磚-config.xml中rhsHeader.jsp一些值,並基於該值我想要顯示的選項(即阻止,編輯或刪除)

示例:如果我想向用戶顯示Compose選項,我只需從tiles-config.xml傳遞值(即headerShowIcons ='compose')並在JSP中使用它。如果我想要顯示Block,我將傳遞headerShowIcons ='block',它將被rhsHeader.jsp讀取以顯示Block選項。我希望這將是更清晰

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

回答

0

我會選擇做不同的方式,但如果它是你想要的,請參見下面的

瓷磚-config.xml中

<tiles-definitions> 
    <definition name="app.base" template="/WEB-INF/views/default/default.jsp"> 
     <put-attribute name="title" value="Not Found" /> 
     <put-attribute name="headerShowIcons" value="" /> 
     <put-attribute ..........> 
    </definition> 
    <definition name="home" extends="app.base"> 
     <put-attribute name="title" value="Home Page" /> 
     <put-attribute name="headerShowIcons" value="edit" /> 
     <put-attribute ..........> 
    </definition> 
</tiles-definitions> 

回到Home.jsp

<c:set var="var"><tiles:insertAttribute name="headerShowIcons"/></c:set> 

<c:choose> 
    <c:when test="${'refine' == var}"> 
      <li><a href="#" class="refine">Refine</a></li> 
    </c:when> 
    <c:when test="${'block' == var}"> 
     <li><a href="#" class="block">Block</a></li> 
    </c:when> 
    <c:when test="${'edit' == var}"> 
     <li><a href="javaScript:void(0);" class="edit">Edit</a></li> 
    </c:when> 
    <c:when test="${'delete' == var}"> 
     <li><a href="javaScript:void(0);" class="delete">Delete</a></li> 
    </c:when> 
    <c:otherwise> 
     <p>test</p> 
    </c:otherwise> 
</c:choose> 

如果您願意,可以將其移至layout.jsp並相應地顯示您的標題

+0

我已經編輯了問題,我想這會更清楚了。 –

+0

@ balboa_21看到更新回答 – QGA

+0

請看問題的大膽部分。[有什麼辦法嗎?] –

1

我終於找到了解決辦法要做到這一點,我認爲這可能有助於有人用這樣的要求:

,我們將不得不使用

headerLayout.jsp

<tiles:useAttribute name="whatToShow"/> 
    <header> 
    <div> 
     <tiles:insertAttribute name="lhsHeader" /> 
     <tiles:insertAttribute name="rhsHeader"> 
      <tiles:putAttribute name="whatToShow">${whatToShow}</tiles:putAttribute> 
     </tiles:insertAttribute> 
    </div> 
    </header> 
<div> 
    <tiles:insertAttribute name="body"/> 
</div> 

瓷磚,config.jsp中

<definition name="Header.*" template="/{1}/layouts/headerLayout.jsp"> 
    <put-attribute name="lhsHeader" value="/s/headerWithBack.jsp"/> 
    <put-attribute name="rhsHeader" value="/s/rhsHeader.jsp"/> 
    <put-attribute name="body" value=""/> 
    <put-attribute name="whatToShow" value="block" type="string"/> 
</definition> 
<!-- inside the definition under whatToShow, I just write whatever value(block,edit,delete,etc) I want to pass to the rhsHeader.jsp --> 

rhsHeader.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<tiles:useAttribute name="whatToShow"/> 
<div class="RHS"> 
<ul> 
    <c:choose> 
     <c:when test="${whatToShow eq 'refine'}"> 
      <li><a href="#" class="refine">Refine</a></li> 
     </c:when> 
     <c:when test="${whatToShow == 'block'}"> 
      <li><a href="#" class="block">Block</a></li> 
     </c:when> 
     <c:when test="${whatToShow eq 'edit'}"> 
      <li><a href="javaScript:void(0);" class="edit">Edit</a></li> 
     </c:when> 
     <c:when test="${whatToShow eq 'delete'}"> 
      <li><a href="javaScript:void(0);" class="delete">Delete</a></li> 
     </c:when> 
     <c:otherwise> 
       <p></p> 
     </c:otherwise> 
    </c:choose> 
    </ul> 
</div> 

PS:我已經使用whatToShow代替headerShowIcons