Results 1 to 7 of 7

Thread: Velocity Configuration

  1. #1
    Join Date
    Feb 2009
    Posts
    1

    Question Velocity Configuration

    Hi !
    Im trying to configure a spring portlet using Velocity. The portlet is to be run under Liferay, I dont know if this is a important fact or not. I have been following the reference manual steps to configure Velocity and I havent reached a solution. Im using velocity-1.6.1.jar and velocity-1.6.1-dep.jar as libraries. I hope somebody could help me !! The error I get is the following:

    ERROR [DispatcherPortlet:501] Could not complete request
    javax.portlet.PortletException: org.springframework.web.util.NestedServletExceptio n: View rendering failed; nested exception is java.lang.IllegalStateException: WebApplicationObjectSupport instance [org.springframework.web.servlet.view.velocity.Velo cityView: name 'view'; URL [/WEB-INF/velocity/view.vm]] does not run within a ServletContext. Make sure the object is fully configured!
    The only file I have modified over my spring portlet (running) is the name-portlet.xml, I use (..) where URLs are because I cannot post them:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans  (...) xsi:schemaLocation="(...)/spring-beans-2.5.xsd  (...)/spring-context-2.5.xsd">
    
      <context:annotation-config/>
    
      <bean class="org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="interceptors">
          <bean class="org.springframework.web.portlet.handler.ParameterMappingInterceptor"/>
        </property>
      </bean>
    
    
      <bean id="viewController" class="es.prueba.portlet.pruebaAlba2Controller" />
    
      <bean id="portletModeHandlerMapping"	class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
    	  <property name="portletModeMap">
    		  <map>
    			  <entry key="view" value-ref="viewController" />
    		  </map>
    	  </property>
      </bean>
    
      <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="resourceLoaderPath">
            <value>/</value>
        </property>
      </bean>
    
     <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
    	<property name="prefix" value="/WEB-INF/velocity/"/>
        <property name="cache" value="false"/>
        <property name="suffix" value=".vm"/>
      </bean>
    
    </beans>

    The web.xml file contains the spring reference manual indications:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" (...) xsi:schemaLocation="(...)/web-app_2_4.xsd">    
        <servlet>
    		<servlet-name>view-servlet</servlet-name>
    		<servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
    		<load-on-startup>0</load-on-startup>
    	</servlet>
    	
    	<servlet-mapping>
    		<servlet-name>view-servlet</servlet-name>
    		<url-pattern>/WEB-INF/servlet/view</url-pattern>
    	</servlet-mapping>
    </web-app>

    Please HELP !!! I cannot figure out where is the problem !

  2. #2
    Join Date
    Aug 2009
    Posts
    1

    Default I met the same quesion

    Hope somebody could help me

  3. #3
    Join Date
    Sep 2010
    Posts
    1

    Default

    Hello!

    I have pretty much the same situation, hope somebody has an idea on what's missing.
    Thanks in advance!

  4. #4
    Join Date
    Dec 2010
    Posts
    4

    Default

    Hello all,

    I will appreciate sharing the solution to this problem.

    Warm regards

    Younes

  5. #5
    Join Date
    Sep 2005
    Location
    Webster Groves, MO
    Posts
    95

    Default

    I'm having this issue as well. I haven't found a solution for this anywhere, nor have I found any info on using the VelocityViewResolver and VelocityView classes within a portlet configuration. The portlet itself is working. I converted to using vm templates by changing the view resolver as described in the Spring documentation, then creating some basic Velocity templates with little functionality just to get them loading. But I can't get even these basic templates loading. Instead I get the same error message described above:

    Code:
    20:05:06,744 ERROR [PortletRequestDispatcherImpl:108] org.springframework.web.util.NestedServletException: View rendering failed; nested exception is java.lang.IllegalStateException: WebApplicationObjectSupport instance [org.springframework.web.servlet.view.velocity.VelocityView: name 'home'; URL [home.vm]] does not run within a ServletContext. Make sure the object is fully configured!
    org.springframework.web.util.NestedServletException: View rendering failed; nested exception is java.lang.IllegalStateException: WebApplicationObjectSupport instance [org.springframework.web.servlet.view.velocity.VelocityView: name 'home'; URL [home.vm]] does not run within a ServletContext. Make sure the object is fully configured!
    I looked at all of the properties on the VelocityConfigurer and VelocityViewResolver classes and don't see anything that would resolve this. Any help would be greatly appreciated.
    Last edited by rherrick; Apr 28th, 2011 at 01:51 PM.
    Rick Herrick

  6. #6
    Join Date
    Sep 2005
    Location
    Webster Groves, MO
    Posts
    95

    Lightbulb

    Hopefully this will help other people running into this error. I finally got the solution thanks to a lot of help on this thread on the Liferay forum.

    The basic issue is that the ContextLoaderListener, along with the contextConfigLocation parameter, was missing in the web.xml file. I'd bet people were running into this issue because they were working off a few tutorials that don't include this in the web.xml set up (that's where my issue came from). So to fix this, all you need to do is add this to your web.xml:

    HTML Code:
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/*-portlet.xml</param-value>
    </context-param>
    
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    The reason this is hard to track down is that the portlet-name-portlet.xml context configuration file seems to get loaded by the Spring DispatcherPortlet class automatically, so everything in there seems to be working properly. But without the context configuration listener, apparently the application context doesn't get propagated properly. This works OK with JSPs, at least up to the point where I had mine, but not with Velocity templates.

    For reference purposes, I've attached a simple working portlet project to this thread. Hopefully this will help others who run into this problem. One note on this sample code: there's a <taglib> element in the web.xml that will break this portlet when deployed in non-Liferay portals, e.g. GateIn. Just delete the entire <taglib> element from the web.xml and it should work fine. The requirement for that element is a bug in the Liferay IDE development tools.

    OK, fabulous, on to break a few more things as I slog through this
    Attached Files Attached Files
    Rick Herrick

  7. #7

    Default

    Hi, I am also getting same issue, when i integrating with DWR. Please help me on this.

Tags for this Thread

Posting Permissions

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