Announcement Announcement Module
Collapse
No announcement yet.
how to order VelocityViewResolver and InternalResourceViewResolver ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


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

      Comment


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

        Comment


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

          Comment

          Working...
          X