Announcement Announcement Module
No announcement yet.
Problem with multiple ViewResolvers and Tiles2 Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with multiple ViewResolvers and Tiles2

    I'm using Spring2.5.4, Spring Web MVC, Tiles2 and configured Tiles2 with TilesConfigurer. To display jsp pages I'm using UrlBasedViewResolver. Everything worked fine until I have decided to use additional InternalResourceViewResolver to display information retrieved from AJAX requests which doesn't require Tiles templates. When I'm trying to display results from AJAX requests, I'm getting the following exception:
    org.apache.tiles.definition.NoSuchDefinitionExcept ion: debtorsearchresults,
    where searchresults is a view name returned from SearchController in a ModelAndView object.

    As it said in documentation,

    "If a specific view resolver does not result in a view, Spring will inspect the context to see if other view resolvers are configured. If there are additional view resolvers, it will continue to inspect them. If not, it will throw an Exception."

    But in my case it seems like Exception is being thrown after first unsuccessful attempt of Tiles configurer to find a definition.
    Here is my configuration xml:
    HTML Code:
    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="order" value="1" />
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />		
    <bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="order" value="0" />
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />				
    The full exception stack trace:

    org.apache.tiles.definition.NoSuchDefinitionException: debtorsearchresults
    	at org.apache.tiles.impl.BasicTilesContainer.render(
    	at org.apache.tiles.impl.BasicTilesContainer.render(
    	at org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(
    	at org.springframework.web.servlet.view.AbstractView.render(
    	at org.springframework.web.servlet.DispatcherServlet.render(
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(
    	at org.springframework.web.servlet.DispatcherServlet.doService(
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(
    	at org.springframework.web.servlet.FrameworkServlet.doGet(
    	at javax.servlet.http.HttpServlet.service(
    	at javax.servlet.http.HttpServlet.service(
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(
    	at org.apache.catalina.core.StandardWrapperValve.invoke(
    	at org.apache.catalina.core.StandardContextValve.invoke(
    	at org.apache.catalina.core.StandardHostValve.invoke(
    	at org.apache.catalina.valves.ErrorReportValve.invoke(
    	at org.apache.catalina.core.StandardEngineValve.invoke(
    	at org.apache.catalina.connector.CoyoteAdapter.service(
    	at org.apache.coyote.http11.Http11Processor.process(
    	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(
    	at org.apache.tomcat.util.threads.ThreadPool$
    	at Source)

  • #2
    The problem is the InternalResourceViewResolver and the UrlBasedViewResolver need to be configured as the last view resolver in a chain. So I don't think you can mix these two resolvers.


    • #3
      Documentation says that only InternalResourceViewResolver must be configured as the last.


      • #4 Check out the note section. "Note: When chaining ViewResolvers, a UrlBasedViewResolver always needs to be last, as it will attempt to resolve any view name, no matter whether the underlying resource actually exists. "


        • #5
          Thanks. How could I forget to read docs about UrlBasedViewResolver? Now it's clear.


          • #6
            But does it have to be that way? Why must a tiles view resolver be an all-or-nothing UrlBasedViewResolver? It seems like we could write one that check the Tiles Config Factory, and if the view defn is not there it would return null and continue on to the next view resolver.

            I too would like to mix Tiles views with simple JSP views, and I'm finding this to be a roadblock.


            • #7
              Ha, figured it out. If we use the convention the all of our Tiles views follow the naming pattern ".*" (like in the Old Days), then we can set a view resolver like this:

              <bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
              	<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
              	<property name="order" value="1"/>
              	<property name="viewNames" value=".*"/>
              Now I can keep my "normal" JSP InternalResourceViewResolver at the end of the chain, and Tiles views and regular JSP views can co-mingle.

              I love it when I don't have to write code!