Tiles 3 view resolver issue with Spring 3.2 mvc

4.3k views Asked by At

I'm new to Tiles and Spring MVC. I've a problem with display (I looked through several similar issues but found no solution for 'my problem'). Here is my 'tiles-servlet.xml' configuration (tried with UrlBasedViewResolver and TilesViewResolver).

....
<bean id="viewResolver" class="org.springframework.web.servlet.view.tiles3.TilesViewResolver">  
    <property name="viewClass">  
        <value>org.springframework.web.servlet.view.tiles3.TilesView</value>  
    </property>  
</bean>

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">  
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles.xml</value>
            <value>/WEB-INF/tiles-booking.xml</value>
        </list>  
    </property>  
</bean> 
....

My 'tiles.xml' containing the Tiles definitions

<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE tiles-definitions PUBLIC  "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"  "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>  
    <definition name="base.definition" template="/WEB-INF/tiles/template/defaultLayout.jsp">  
        <put-attribute name="title" value="" />  
        <put-attribute name="header" value="/WEB-INF/tiles/template/defaultHeader.jsp" />  
        <put-attribute name="search" value="/WEB-INF/search/searchCriteria.jsp" />  
        <put-attribute name="searchResults" value="/WEB-INF/search/searchResults.jsp" />  
        <put-attribute name="unitDetails" value="/WEB-INF/search/unitDetails.jsp" />  
        <put-attribute name="footer" value="/WEB-INF/tiles/template/defaultFooter.jsp" />  
        <put-attribute name="body" value="/WEB-INF/tiles/template/defaultContent.jsp" />  
    </definition>

    <definition name="indexPage" template="/WEB-INF/tiles/template/simpleLayout.jsp">
        <put-attribute name="header" value="/WEB-INF/tiles/template/defaultHeader.jsp" />  
        <put-attribute name="title" value="Welcome to Venue Bookings" />
        <put-attribute name="indexPage" value="/WEB-INF/jsp/indexPage.jsp" />  
        <put-attribute name="footer" value="/WEB-INF/tiles/template/defaultFooter.jsp" />  
    </definition>

    <definition name="searchForm" extends="base.definition">
        <put-attribute name="title" value="Search form" />  
        <put-attribute name="search" value="/WEB-INF/search/searchCriteria.jsp" />  
        <put-attribute name="searchResults" value="/WEB-INF/search/searchResults.jsp" />  
        <put-attribute name="unitDetails" value="/WEB-INF/search/unitDetails.jsp" />  
    </definition>  

    <definition name="bookConfirmationForm" extends="/WEB-INF/tiles/template/bookingLayout.jsp">
        <put-attribute name="title" value="Booking Confirmation" />  
        <put-attribute name="booking" value="/WEB-INF/search/configmBooking.jsp" />  
    </definition>  

</tiles-definitions>

I have all the specified JSP files defined, working and are available. All those have been working for quiet some time, non issues. However, yesterday I defined to display a new page for booking. I'm facing error:

  • When I comment the definition 'bookConfirmationForm' (as above), everything works fine. Strange, if I enable this definition, I face the issues with the home page itself ('indexPage' view is my start page).
  • When I comment the above definition, things work fine until I reach the above view and obviously, it fails there.

Here is the exception:

org.apache.jasper.JasperException: javax.servlet.ServletException: Could not resolve view with name 'indexPage' in servlet with name 'tiles'
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:585)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause: javax.servlet.ServletException: Could not resolve view with name 'indexPage' in servlet with name 'tiles'
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1190)

Finally, my controller methods:

@RequestMapping(value = "/index")
public ModelAndView indexPage() {
    Map<String, Object> model = new HashMap<String, Object>();
    ....
    model.put("command", new SearchCriteriaBean());
    return new ModelAndView("indexPage", model);
}

@RequestMapping(value = "/checkAvailability", method = RequestMethod.GET)
public ModelAndView checkAvailability(@ModelAttribute("agreedBookingRequest") 
    UnitBookingAgreementBean agreedBookingRequest, HttpSession session) {
    .....
        return new ModelAndView("bookConfirmationForm", model);
}

I think that the mistake must be a stupid one, but I'm unable to figure it out. I tried with tiles2 as well, but that didn't help.

1

There are 1 answers

2
Ralph On BEST ANSWER

The extends="/WEB-INF/tiles/template/bookingLayout.jsp" for the "bookConfirmationForm" definition looks strange for me (<definition name="bookConfirmationForm" extends="/WEB-INF/tiles/template/bookingLayout.jsp">). I only know that one can use logical names, for the extends parameter, but not file names.

I guess you wanted to write extends="base.definition" instead, or wanted to use the template parameter:

<definition name="bookConfirmationForm" extends="base.definition">
    <put-attribute name="title" value="Booking Confirmation" />  
    <put-attribute name="booking" value="/WEB-INF/search/configmBooking.jsp" />  
</definition>  

<!-- or -->

<definition name="bookConfirmationForm" template="/WEB-INF/tiles/template/bookingLayout.jsp">
    <put-attribute name="title" value="Booking Confirmation" />  
    <put-attribute name="booking" value="/WEB-INF/search/configmBooking.jsp" />  
</definition>