2014-03-25 204 views
0

我正嘗試構建一個具有嵌套圖塊的應用程序。tiles:insertAttribute引發異常

tiles.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" 
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd"> 
<tiles-definitions> 
<definition name="base.defination" template="/WEB-INF/jsp/layout.jsp"> 
<put-attribute name="title" value="Ashoka Travels"/> 
<put-attribute name="header" value="/WEB-INF/jsp/header.jsp"/> 
<put-attribute name="body" value=""/> 
<put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp"/> 
</definition> 

     <definition name="transportBody" extends="base.defination"> 
       <put-attribute name="body" value="/WEB-INF/jsp/transportMain.jsp" cascade="true"/> 

     </definition> 

     <definition name="booking" extends="transportBody"> 
         <put-attribute name="bookingRadio" value="/WEB-INF/jsp/bookingLayout.jsp" cascade="true"/> 

     </definition> 

     <definition name="transportBodyHeader" extends="booking"> 
       <put-attribute name="HeaderBookingTypeSelect" value="/WEB-INF/jsp/primaryPage/bookingTypeSelect.jsp" cascade="true"/> 
       <put-attribute name="BodyTransportSelector" value="/WEB-INF/jsp/primaryPage/bookingTransportSelect.jsp" cascade="true"/> 
       <put-attribute name="FooterTransportSelectorBooking" value="/WEB-INF/jsp/primaryPage/bookingTransportSearch.jsp" cascade="true"/> 
     </definition> 

</tiles-definitions> 

bookingLayout.jsp

<body> 
<div id="transportBookingLayout"> 
      <div><tiles:insertAttribute name="HeaderBookingTypeSelect"/></div> 
      <div><tiles:insertAttribute name="BodyTransportSelector"/></div> 
      <div><tiles:insertAttribute name="FooterTransportSelectorBooking"/></div> 
</div> 
</body> 

這是transportMain頁面,其包括通過<tiles:insertAttribute>另一個JSP頁:

<body> 
    <div id="mainTransport" style="border:1px solid red"> 
     <div id="ticketBookingDiv" class="bookTicket" > 

      <%-- <jsp:include page="/WEB-INF/jsp/primaryPage/hello.jsp" flush="true"/> --%> 
     <tiles:insertAttribute name="bookingRadio"></tiles:insertAttribute> 
     </div> 

    </div> 
    </body> 

我得到這個異常:

 
Servlet.service() for servlet [SpringMVC] in context with path [/Travels_SpringMVC] threw exception [An exception occurred processing JSP page /WEB-INF/jsp/transportMain.jsp at line 32 

29:   
30:   
31:    --%> 
32:   
33:   
34:  
35: 


Stacktrace:] with root cause 
org.apache.tiles.template.NoSuchAttributeException: Attribute 'bookingRadio' not found.
+0

你想顯示的看法? – jpprade

+0

transportMain在佈局(主佈局)的主體屬性中。 transportMain本身就是一個佈局,它具有預訂無線屬性,其中包括「預訂」另一個佈局。每當我運行它都會拋出一個異常「bookingRadio」找不到。所以要回答你的問題,transportMain將顯示哪些包括「bookingLayout.jsp」 –

+0

transportMain是一個jsp,我的意思是什麼是邏輯視圖名稱?由於transportBody聲明瞭一個預訂無線網絡,但沒有放置任何屬性 – jpprade

回答

0
**nested Tiles is working fine.Here is the solution.** 
**tiles.xml**<tiles-definitions> 
<definition name="base.defination" template="/WEB-INF/jsp/layout.jsp"> 
<put-attribute name="title" value="Asoka.com"/> 
<put-attribute name="header" value="/WEB-INF/jsp/header.jsp"/> 
<put-attribute name="body" value=""/> 
<put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp"/> 
</definition> 

     <definition name="transportMain" extends="base.defination" > 
       <put-attribute name="body"> 
        <definition template="/WEB-INF/jsp/transportMain.jsp" name="mainTransport" extends="transportMain"> 
         <put-attribute name="bookingRadio"> 
          <definition template="/WEB-INF/jsp/primaryPage/bookingLayout.jsp" name="layoutBooking" extends="mainTransport"> 
           <put-attribute name="HeaderBookingTypeSelect" value="/WEB-INF/jsp/primaryPage/bookingTypeSelect.jsp" cascade="true"/> 
           <put-attribute name="BodyTransportSelector" value="/WEB-INF/jsp/primaryPage/bookingTransportSelect.jsp" cascade="true"/> 
           <put-attribute name="FooterTransportSelectorBooking" value="/WEB-INF/jsp/primaryPage/bookingTransportSearch.jsp" cascade="true"/> 
          </definition> 
         </put-attribute> 
        </definition> 
       </put-attribute> 
     </definition> 


</tiles-definitions> 

**transportMain.jsp** 

<form:form commandName="transportBookingForm" modelAttribute="transportBookingForm"> 
    <div id="mainTransport" style="border:1px solid red"> 
     <div id="ticketBookingDiv" class="bookTicket" > 
      <tiles:insertAttribute name="bookingRadio"/> 
     </div> 
    </div> 
    </form:form> 
**At Controller level** 

@ModelAttribute("bookingTypeSelect") 
    public ModelAndView booking(@ModelAttribute BookingTypeSelect bookingTypeSelect){ 
     System.out.println("Entered booking"); 
     return new ModelAndView("bookingTypeSelect" ,"bookingTypeSelect",bookingTypeSelect); 
    } 

**bookingLayout.jsp** 

<div id="transportBookingLayout"> 
      <div><tiles:insertAttribute name="HeaderBookingTypeSelect"/></div> 
      <div><tiles:insertAttribute name="BodyTransportSelector"/></div> 
      <div><tiles:insertAttribute name="FooterTransportSelectorBooking"/></div> 
</div>