Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Is there a better way to order ViewResolvers?

  1. #1
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default Is there a better way to order ViewResolvers?

    using Spring 1.1.3. for org.springframework.web.servlet.view.ViewResolver

    Code:
     * <p>Note&#58; 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.
    Ordering of view resolvers seems to be based on their id, so I've got one view resolver called aardvarkViewResolver currently so it fires first.

    Can the Spring team add the Ordered interface into the mix in how view resolvers get called? or alternatively can the order in which view resolvers are defined in the spring config file determine their order?

    I've tried swapping the order in which view resolvers are defined in the Spring config file and it doesn't seem to make any difference.

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Use the order property:

    Code:
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="order"><value>1</value></property>
    </bean>
    Have a look at the org.springframework.util.Ordered interface (I believe it's the util package, but I'm not sure).

    regards,

    Alef Arendsen
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    Doesn't work.

    I know about the Ordered interface, but it's not implemented anywhere in the ViewResolver class hierarchy right up to the top level.

  4. #4
    Join Date
    Feb 2005
    Location
    Fribourg / Switzerland
    Posts
    1

    Default

    Doesn't work.

    I know about the Ordered interface, but it's not implemented anywhere in the ViewResolver class hierarchy right up to the top level.
    I have the same problem. I don't understand, the chapter 12.5.2 (chaining viewResolvers) gives an example which use the order property !

    When I try I get:

    Code:
    org.springframework.beans.factory.BeanCreationException&#58; Error creating bean with name 'viewResolver' defined in ServletContext resource &#91;/WEB-INF/cms-servlet.xml&#93;&#58; Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException&#58; Invalid property 'order' of bean class &#91;org.springframework.web.servlet.view.InternalResourceViewResolver&#93;&#58; Bean property 'order' is not writable or has an invalid setter method&#58; Does the parameter type of the setter match the return type of the getter?
    The reference doc is not up-to-date ?!?

  5. #5
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Sorry about that. The view resolvers that don't implement the ordered interface, end up at the end of the chain. All view resolvers that inherently need to be at the end of the chain (because they can't decide themselves whether or not a resource exists - e.g. with an InternalResourceViewResolver that uses the RequestDispatcher to dispatch to an internal resource, which won't return an exception or something, but instead send a 404 to the browser) do not implement that ordered interface.

    Have a look at the JavaDoc for the view resolver you're using to see if it implements the interface. They also mention whether or not they need to be last in the chain.

    regards,
    Alef
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  6. #6
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    I'll modify the docs as well, thanks for spotting this!
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  7. #7
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Hmmm, additional info. There ARE view resolvers that implement the interface. Have a look at the resourcebundleview resolver for example.
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  8. #8
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    Thanks for that.

    I implemented the Ordered interface like you suggested and our ViewResolver now gets called before the catch-all one.

  9. #9
    Join Date
    Jul 2005
    Posts
    2

    Default

    Bump.

    Reference doc, 12.5.2. Chaining ViewResolvers still needs updating.

    I just spent a while trying to figure out why InternalResourceViewResolver didnt support the order property that was mentioned, before finding the answer here.

  10. #10
    Join Date
    Jul 2005
    Posts
    4

    Default

    Quote Originally Posted by ericp
    Reference doc, 12.5.2. Chaining ViewResolvers still needs updating.

    I just spent a while trying to figure out why InternalResourceViewResolver didnt support the order property that was mentioned, before finding the answer here.
    Me too, I just did the same.

    It is unfortunate that there is the example configuration fragment in the reference manual that fails at application context setup. The same error is in Spring in Action (page 314, "Using multiple view resolvers").

    Let's hope that it is a rare occasion that the example code is something guaranteed to fail
    Timo Rantalaiho
    Reaktor

Similar Threads

  1. Replies: 5
    Last Post: Sep 28th, 2005, 10:11 AM
  2. hibernate pagination
    By oliverchua in forum Data
    Replies: 8
    Last Post: Sep 23rd, 2005, 06:06 PM
  3. order of validation messages
    By georgey in forum Swing
    Replies: 0
    Last Post: Aug 31st, 2005, 08:23 AM
  4. Loading Beans in Order
    By mallupappi in forum Container
    Replies: 2
    Last Post: Mar 31st, 2005, 07:23 AM
  5. Bean destruction order
    By ugo in forum Container
    Replies: 2
    Last Post: Oct 20th, 2004, 06:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •