Announcement Announcement Module
Collapse
No announcement yet.
Can we use More than One view Resolvers in the same web app? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can we use More than One view Resolvers in the same web app?

    i need two view resolvers for the purposes:
    one to resolve jsp resouces,the other to resolve views like PDF resources,
    so i declared the following in the configuration file:
    <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="viewClass"><value>org.springframework.web.se rvlet.view.JstlView</value></property>
    <property name="prefix"><value>/WEB-INF/jsp/</value></property>
    <property name="suffix"><value>.jsp</value></property>
    </bean>

    <bean id="resourceBundleViewResolver"class="org.springfr amework.web.servlet.view.ResourceBundleViewResolve r">
    <property name="basename"><value>views-myapp</value></property>
    <property name="order"><value>0</value></property>
    </bean>
    ......
    But actually the web app always only use the first view resolver to resolve all the view names.
    is it true that there's no way to specify A resolver to resolve A type of view names and B resolver to resolve B type of view names?

  • #2
    You can use multiple view resolvers. Internally, Spring looks for all bean definitions of ViewResolver and gives each view resolver a chance to resolve the view.

    You should change the order of your view resolvers so that the InternalResourceViewResolver is last. You can do this by setting the order property of the ResourceBundleViewResolver to 0.

    Rob

    Comment


    • #3
      it's my fault

      Originally posted by robh
      You should change the order of your view resolvers so that the InternalResourceViewResolver is last. You can do this by setting the order property of the ResourceBundleViewResolver to 0.

      Rob
      Thanks,Rob. it really worked well. Sorry,actrually i didn't add the order property,so the post was not the case.Now i know what the order property really means.But i still propose to expressly declare which view resolver to resolve which views in the file by some way.

      Comment


      • #4
        Using ViewResolvers for plain JSP and Tiles2

        I am using Tiles2 as a view resolver. I need to invoke plain jsp if there is no tiles definition for a URL . I tried using 2 view Resolvers but only the view resolver with <property name="order" value="0"/> is called the second view resolve is ignored. How can i make the second view resolver work if the first one fails.

        <bean id="tilesViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedVie wResolver">
        <property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAj axTilesView"/>
        <property name="order" value="1"/>
        </bean>
        <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
        <property name="viewClass"><value>org.springframework.web.se rvlet.view.JstlView</value></property>
        <property name="prefix"><value>/WEB-INF/jsp/</value></property>
        <property name="suffix"><value>.jsp</value></property>
        <property name="order" value="0"/>
        </bean>

        Comment


        • #5
          Please use [ code][/code ] tags when posting code.

          You cannot use the AjaxUrlBasedViewResolver and the InternalResourceViewResolver together. They both are a sub class of the UrlBasedViewResolver. That kind of ViewResolver don't check for the existince of the views (they even cannot). They just generate an URL and delegate to the servlet container to render the generated URL.

          So you will have to find another way to resolve your views. Take a look at the ResourceBundleViewResolver.

          Comment


          • #6
            Can u give me more details

            Can u give me more details how to use ResourceBundleViewResolver in this situation. I need to use the AjaxUrlBasedViewResolver because I am using the AJAX fragment refresh. Do u have any sample configuration for the same

            Comment


            • #7
              Simply use the ResourceBundleViewResolver instead of your InternalResourceViewResolver you could reaplce both if you need. The reference guide and the javadocs of the ResourceBundleViewResolver explains how to use/configure it.

              Comment


              • #8
                The details was of great help

                I used the ResourceBundleViewResolver to resolve all plain JSP. Thanks a lot for the help

                Comment

                Working...
                X