Results 1 to 5 of 5

Thread: how to order VelocityViewResolver and InternalResourceViewResolver ?

  1. #1
    Join Date
    May 2006
    Posts
    18

    Default how to order VelocityViewResolver and InternalResourceViewResolver ?

    I have a project using Spring. Veloicty is used as an normal view tech while a PDF view is also needed. So I need two two solvers.

    Can anybody show me how to setup how to order VelocityViewResolver and InternalResourceViewResolver ?

    I read the document which says both of the ersolvers always needs to be last!

    Thank you in advance.

  2. #2
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default

    the document is right, you can't use them both together. Use either a ResourceBundleViewResolver or an XmlViewResolver for your PDF (or other uncommon views), falling back to the VelocityViewResolver as your default.
    Darren Davison.
    Public Key: 0xE855B3EA

  3. #3
    Join Date
    May 2006
    Posts
    18

    Default

    Thanks davision.

    Here is my configuration:

    <bean id="resourceBundleViewResolver"
    class="org.springframework.web.servlet.view.Resour ceBundleViewResolver">
    <property name="basename" value="views"/>
    <property name="order" value="0"/>
    </bean>


    <bean id="velocityResolver"
    class="org.springframework.web.servlet.view.veloci ty.VelocityLayoutViewResolver">
    <property name="prefix" value=""/>
    <property name="suffix" value=".vm"/>
    <property name="exposeSpringMacroHelpers" value="true"/>
    <property name="requestContextAttribute" value="rc"/>
    <property name="dateToolAttribute" value="date"/>
    <property name="numberToolAttribute" value="number"/>
    <property name="toolboxConfigLocation" value="/WEB-INF/velocity/toolbox.xml"/>
    </bean>

    And I got the exception:
    rg.springframework.web.util.NestedServletException : Request processing failed; nested exception is org.springframework.beans.factory.BeanNotOfRequire dTypeException: Bean named 'index' must be of type [org.springframework.web.servlet.View], but was actually of type [ca.gc.publiservice.letterBuilder.web.IndexControll er]
    org.springframework.beans.factory.BeanNotOfRequire dTypeException: Bean named 'index' must be of type [org.springframework.web.servlet.View], but was actually of type [ca.gc.publiservice.letterBuilder.web.IndexControll er]

    It seems that the fallingback function does not work.

  4. #4
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default

    sounds like you have a controller in your XML config named "index" and a view in your views.properties named "index" also. Try changing one of them.
    Darren Davison.
    Public Key: 0xE855B3EA

  5. #5
    Join Date
    May 2006
    Posts
    18

    Default

    Look at the snippet from package org.springframework.web.servlet.view

    public class ResourceBundleViewResolver extends AbstractCachingViewResolver implements Ordered, DisposableBean {

    ...
    protected View loadView(String viewName, Locale locale) throws Exception {
    BeanFactory factory = initFactory(locale);
    try {
    return (View) factory.getBean(viewName, View.class);
    }
    catch (NoSuchBeanDefinitionException ex) {
    // to allow for ViewResolver chaining
    return null;
    }
    }
    ..
    }

    It looks up the view from factory.getBean with the Veiw.class type! that's error said.
    And in the beans xml file, I do have:

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="interceptors">
    <list>
    <ref bean="localeChangeInterceptor"/>
    </list>
    </property>
    <property name="mappings">
    <props>
    <prop key="/index.htm">index</prop>
    ...
    </props>
    </property>
    </bean>

    <bean id="index" class="ca.gc.publiservice.letterBuilder.web.IndexC ontroller"/>

    Furthermore, in the Contooller, the view name returned is "index" ! So, when Spring looks up the index, it trown the exception.

    change the IndexController id to indexController (I mean make the id is deffrent from the view name) fixed the problem.

    The weird thing I can not understaned is, when Spring is trying to find view from beanFactory.

Posting Permissions

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