Fórum
Problem with simple spring MVC portlet
Johannes Hipp, modificado 14 Anos atrás.
Problem with simple spring MVC portlet
Junior Member Postagens: 38 Data de Entrada: 06/02/10 Postagens Recentes
Hello,
I try to deploy a simple spring portlet in ext (I can't use Plugins SDK...).
Edit:
It looks so:
ext-impl/src:
Package: com.robisoft.springsample.controllers
HelloSpringController.java
ext-lib/portal:
- commons-logging.jar
- spring-webmvc-portlet.jar
- spring-webmvc.jar
- spring.jar
ext-web-docroot-html-portlet-ext-hellospring:
init.jsp
view.jsp
ext-web-docroot-WEB-INF/context
applicationContext.xml
hellospring-portlet.xml
portlet-ext.xml
liferay-portlet-ext.xml
web.xml
Thank you!
Best regards,
Johannes
I try to deploy a simple spring portlet in ext (I can't use Plugins SDK...).
Edit:
It looks so:
ext-impl/src:
Package: com.robisoft.springsample.controllers
HelloSpringController.java
package com.robisoft.springsample.controllers;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.portlet.mvc.ParameterizableViewController;
public class HelloSpringController extends ParameterizableViewController{
@Override
protected ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response)
throws Exception {
return( new ModelAndView(this.getViewName()));
}
}
ext-lib/portal:
- commons-logging.jar
- spring-webmvc-portlet.jar
- spring-webmvc.jar
- spring.jar
ext-web-docroot-html-portlet-ext-hellospring:
init.jsp
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<portlet:defineobjects />
<style type="text/css">
<%@ include file="/css/style.css" %>
</style>
view.jsp
<%@ include file="init.jsp" %>
<div class="spring-time">Hello World, from Spring Source<br>
<a href="http://springsource.com" target="_blank"><img src="/images/springSource.png" alt="Spring Source"></a>
</div>
ext-web-docroot-WEB-INF/context
applicationContext.xml
<!--?xml version="1.0" encoding="UTF-8" ?-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" />
hellospring-portlet.xml
<!--?xml version="1.0" encoding="UTF-8"?-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="HelloSpringController" class="com.robisoft.springsample.controllers.HelloSpringController">
<property name="viewName" value="view" />
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="cache" value="true" />
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/html/portlet/ext/hellospring/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
<property name="portletModeMap">
<map>
<entry key="view"><ref local="HelloSpringController" /></entry>
</map>
</property>
</bean>
</beans>
portlet-ext.xml
<portlet>
<portlet-name>hellospring</portlet-name>
<display-name>Hello From Spring</display-name>
<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
<init-param>
<name>contextConfigLocation</name>
<value>/WEB-INF/context/hellospring-portlet.xml</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
</supports>
<portlet-info>
<title>Hello Spring</title>
<short-title>Hello Spring</short-title>
<keywords>hello,spring,sample</keywords>
</portlet-info>
<security-role-ref>
<role-name>administrator</role-name>
</security-role-ref>
<security-role-ref>
<role-name>guest</role-name>
</security-role-ref>
<security-role-ref>
<role-name>power-user</role-name>
</security-role-ref>
<security-role-ref>
<role-name>user</role-name>
</security-role-ref>
</portlet>
liferay-portlet-ext.xml
<portlet>
<portlet-name>hellospring</portlet-name>
<use-default-template>true</use-default-template>
<restore-current-view>true</restore-current-view>
<private-request-attributes>false</private-request-attributes>
<private-session-attributes>false</private-session-attributes>
<render-weight>1</render-weight>
</portlet>
web.xml
<!--?xml version="1.0" encoding="UTF-8"?-->
<web-app>
<!-- Resources bundle base class -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/context/applicationContext.xml
</param-value>
</context-param>
<!-- Servlets -->
<servlet>
<servlet-name>ViewRendererServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ViewRendererServlet</servlet-name>
<url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping>
</web-app>
Thank you!
Best regards,
Johannes
Sebastian Konkol, modificado 14 Anos atrás.
RE: Problem with simple spring MVC portlet
Junior Member Postagens: 34 Data de Entrada: 20/03/09 Postagens Recentes
Hi Johannes,
Are you deploying portlet or application...???? look at the lines:
Best regards
Sebastian Konkol
Are you deploying portlet or application...???? look at the lines:
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Best regards
Sebastian Konkol
Johannes Hipp, modificado 14 Anos atrás.
RE: Problem with simple spring MVC portlet
Junior Member Postagens: 38 Data de Entrada: 06/02/10 Postagens Recentes
Hi Sebastian,
thanks for reply! I'm deploying a portlet, so this should be right or?
thanks for reply! I'm deploying a portlet, so this should be right or?
Sebastian Konkol, modificado 14 Anos atrás.
RE: Problem with simple spring MVC portlet
Junior Member Postagens: 34 Data de Entrada: 20/03/09 Postagens Recentes
Hi Johannes,
You might consider modifying following web.xml:
At least check differences to see what is wrong ;-)
Best regards
Sebastian Konkol
You might consider modifying following web.xml:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" xsi:schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<display-name>w2i-certificates</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/context/applicationContext.xml
</param-value>
</context-param>
<!-- Listeners -->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
com.liferay.portal.kernel.servlet.PortletContextListener
</listener-class>
</listener>
<listener>
<listener-class>flex.messaging.HttpFlexSession
</listener-class>
</listener>
<!-- Servlets -->
<servlet>
<servlet-name>ViewRendererServlet</servlet-name>
<servlet-class>
org.springframework.web.servlet.ViewRendererServlet
</servlet-class>
</servlet>
<servlet>
<servlet-name>myprog</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortletServlet
</servlet-class>
<init-param>
<param-name>portlet-class</param-name>
<param-value>org.springframework.web.portlet.DispatcherPortlet
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ViewRendererServlet</servlet-name>
<url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name> myprog</servlet-name>
<url-pattern>/w2icertificates/*</url-pattern>
</servlet-mapping>
</web-app>
At least check differences to see what is wrong ;-)
Best regards
Sebastian Konkol
Johannes Hipp, modificado 14 Anos atrás.
RE: Problem with simple spring MVC portlet
Junior Member Postagens: 38 Data de Entrada: 06/02/10 Postagens Recentes
Hi Sebastian,
thanks again
Now I've got another problem, seems there is a problem with my listener...
following error:
any ideas?
thanks again
Now I've got another problem, seems there is a problem with my listener...
following error:
Error creating bean with name 'com.liferay.portal.kernel.captcha.CaptchaUtil'
defined in class path resource [META-INF/util-spring.xml]: Cannot create inner bean 'com.liferay.portal
.captcha.CaptchaImpl#79e328' of type [com.liferay.portal.captcha.CaptchaImpl] while setting bean property 'captcha'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.liferay.por
tal.captcha.CaptchaImpl#79e328' defined in class path resource [META-INF/util-spring.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.liferay
.portal.captcha.CaptchaImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
any ideas?
Sebastian Konkol, modificado 14 Anos atrás.
RE: Problem with simple spring MVC portlet
Junior Member Postagens: 34 Data de Entrada: 20/03/09 Postagens Recentes
Hi Johannes,
Looks like constructor of class: com.liferay.portal.captcha.CaptchaImpl is throwing NullPointerException. Don't have idea why - how are you initializing this bean?
Best regards
Sebastian Konkol
Looks like constructor of class: com.liferay.portal.captcha.CaptchaImpl is throwing NullPointerException. Don't have idea why - how are you initializing this bean?
Best regards
Sebastian Konkol
Johannes Hipp, modificado 14 Anos atrás.
RE: Problem with simple spring MVC portlet
Junior Member Postagens: 38 Data de Entrada: 06/02/10 Postagens Recentes
Hmm good question, I don't know why he's initializing this bean... I don't need this bean...
Sebastian Konkol, modificado 14 Anos atrás.
RE: Problem with simple spring MVC portlet
Junior Member Postagens: 34 Data de Entrada: 20/03/09 Postagens Recentes
Hi Johannes,
Can you pack your portlet source and attach it so I can check what could that be?
Best regards
Sebastian Konkol
Can you pack your portlet source and attach it so I can check what could that be?
Best regards
Sebastian Konkol
Johannes Hipp, modificado 14 Anos atrás.
RE: Problem with simple spring MVC portlet
Junior Member Postagens: 38 Data de Entrada: 06/02/10 Postagens Recentes
Hi Sebastion,
that's very nice! I am developing in ext, so I hope I haven't forgotten something...
Thank you very much in advance!
Best regards,
Johannes
that's very nice! I am developing in ext, so I hope I haven't forgotten something...
Thank you very much in advance!
Best regards,
Johannes
Anexos:
Thomas Berg, modificado 14 Anos atrás.
RE: Problem with simple spring MVC portlet
Regular Member Postagens: 131 Data de Entrada: 07/09/09 Postagens Recentes
Hi Johannes,
Controller:
I see nothing wrong with your controller class.
Libraries:
Looks like you've got the required libs.
In portlet-ext.xml you need to add the following (within <portlet></portlet>):
or you can rename the file to "springmvc-portlet.xml"
By default, Spring will look for a file named [portlet-name]-portlet.xml in the WEB-INF folder of your webapp. But if you explicitly define it like above, the name and location can be anything you like.
Although I'm not sure that this is necessary, I think you should place the contents of your current spring-servlet.xml into /WEB-INF/applicationContext.xml. Either way, you have to change the value of the parameters to reflect the location of your jsp's :
The following is an example of what could be in your [portlet-name]-portlet.xml file :
I might have forgotten something so feel free to ask again if you still have problems
(Edit: Added the content of [portlet-name]-portlet.xml)
Regards Thomas
Controller:
I see nothing wrong with your controller class.
Libraries:
Looks like you've got the required libs.
In portlet-ext.xml you need to add the following (within <portlet></portlet>):
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springmvc-servlet.xml</param-value>
</init-param>
or you can rename the file to "springmvc-portlet.xml"
By default, Spring will look for a file named [portlet-name]-portlet.xml in the WEB-INF folder of your webapp. But if you explicitly define it like above, the name and location can be anything you like.
Although I'm not sure that this is necessary, I think you should place the contents of your current spring-servlet.xml into /WEB-INF/applicationContext.xml. Either way, you have to change the value of the parameters to reflect the location of your jsp's :
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/html/portlet/springmvc/jsp/" /> <!--
<property name="suffix" value=".jsp"/>
</bean>
</code></pre><br /><br />If you have more than one portlet in the ext-environment that uses Spring, I guess you need a common folder for the jsp's that can be defined in the above property.<br /><br />Put the following in your <strong>web.xml</strong> :<br /><br /><pre><code><context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value> <!-- Default location so not necessary -->
<!-- Required for Spring portlets to delegate view rendering. -->
<servlet>
<servlet-name>ViewRendererServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ViewRendererServlet</servlet-name>
<url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping></bean>
The following is an example of what could be in your [portlet-name]-portlet.xml file :
<!-- Controllers -->
<bean id="helloWorldController" class="com.ext.portlet.springmvc.HelloWorldController" />
<!-- Handler Mappings -->
<bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
<property name="order" value="20" />
<property name="portletModeMap">
<map>
<entry key="view"><ref bean="helloWorldController" /></entry>
</map>
</property>
</bean>
<!-- Exceptions Handlers -->
<bean id="defaultExceptionHandler" parent="defaultExceptionHandlerTemplate" />
I might have forgotten something so feel free to ask again if you still have problems
(Edit: Added the content of [portlet-name]-portlet.xml)
Regards Thomas
Johannes Hipp, modificado 14 Anos atrás.
RE: Problem with simple spring MVC portlet
Junior Member Postagens: 38 Data de Entrada: 06/02/10 Postagens Recentes
Edit:
Hey, first I wanna thank you both! I removed the listener in the web.xml and changed the things you told me Thomas (see first post).
When do I need a listener in the web.xml?
Best regards,
Johannes
Hey, first I wanna thank you both! I removed the listener in the web.xml and changed the things you told me Thomas (see first post).
When do I need a listener in the web.xml?
Best regards,
Johannes
Michael Toback, modificado 13 Anos atrás.
RE: Problem with simple spring MVC portlet
New Member Postagens: 3 Data de Entrada: 08/06/10 Postagens Recentes
Johannes et al,
I have taken your source and, by following the thread got Liferay to come up without errors.
Where I fall down is trying to add the portlet to a page. The new portlet is not getting added to the list of applications in the category.samples category. All I can "see" when I try to add applications are the four applications defined in the portal liferay-display.xml file. I suspect this is some deficiency in the way I am registering the portlets.
Let me ask these questions:
liferay-display.xml - this is essentially the same file as what is in the portal application, with new portlet added as:
portlet-ext.xml - this file contains the definition of the new portlet as:
liferay-portlet-ext.xml contains only the custom portlets as:
finally hellospring-portlet.xml is a file in the context directory that defines the spring context of the portlet:
So what am I doing wrong?
Michael Toback
I have taken your source and, by following the thread got Liferay to come up without errors.
Where I fall down is trying to add the portlet to a page. The new portlet is not getting added to the list of applications in the category.samples category. All I can "see" when I try to add applications are the four applications defined in the portal liferay-display.xml file. I suspect this is some deficiency in the way I am registering the portlets.
Let me ask these questions:
liferay-display.xml - this is essentially the same file as what is in the portal application, with new portlet added as:
<category name="category.sample">
<portlet id="hellospring" />
</category>
portlet-ext.xml - this file contains the definition of the new portlet as:
<portlet>
<portlet-name>hellospring</portlet-name>
<display-name>Hello From Spring</display-name>
<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
<init-param>
<name>contextConfigLocation</name>
<value>/WEB-INF/context/hellospring-portlet.xml</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
</supports>
<portlet-info>
<title>Hello Spring</title>
<short-title>Hello Spring</short-title>
<keywords>hello,spring,sample</keywords>
</portlet-info>
<security-role-ref>
<role-name>administrator</role-name>
</security-role-ref>
<security-role-ref>
<role-name>guest</role-name>
</security-role-ref>
<security-role-ref>
<role-name>power-user</role-name>
</security-role-ref>
<security-role-ref>
<role-name>user</role-name>
</security-role-ref>
</portlet>
liferay-portlet-ext.xml contains only the custom portlets as:
<portlet>
<portlet-name>hellospring</portlet-name>
<use-default-template>true</use-default-template>
<restore-current-view>true</restore-current-view>
<private-request-attributes>false</private-request-attributes>
<private-session-attributes>false</private-session-attributes>
<render-weight>1</render-weight>
</portlet>
finally hellospring-portlet.xml is a file in the context directory that defines the spring context of the portlet:
<!--?xml version="1.0" encoding="UTF-8"?-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="cache" value="true" />
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
<property name="portletModeMap">
<map>
<entry key="view"><ref local="helloSpringController" /></entry>
</map>
</property>
</bean>
<bean id="helloSpringController" class="com.robisoft.springsample.controllers.HelloSpringController">
<property name="viewName" value="view" />
</bean>
</beans>
So what am I doing wrong?
Michael Toback
asif aftab, modificado 8 Anos atrás.
RE: Problem with simple spring MVC portlet
Regular Member Postagens: 123 Data de Entrada: 02/09/13 Postagens Recentes
Thanks, helpful.