Announcement Announcement Module
Collapse
No announcement yet.
Problem with multiple ViewResolvers and Tiles2 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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">
    <list>
    <value>/WEB-INF/defs/matrix.xml</value>
    </list>
    </property>
    </bean>
    	
    <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>
    	
    <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" />				
    </bean>
    The full exception stack trace:

    Code:
    org.apache.tiles.definition.NoSuchDefinitionException: debtorsearchresults
    	at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:578)
    	at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:246)
    	at org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:75)
    	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:252)
    	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1173)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:901)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
    	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    
    	at java.lang.Thread.run(Unknown 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.

    Comment


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

      Comment


      • #4
        http://static.springframework.org/sp...wResolver.html. 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. "

        Comment


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

          Comment


          • #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.

            Comment


            • #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:

              Code:
              	
              <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=".*"/>
              </bean>
              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!

              Comment

              Working...
              X