我正在尝试构建一个具有嵌套切片的应用程序。
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 :(得分: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>