Forums de discussion
GenericPortlet - how to get an ApplicationContext.
john green bowe, modifié il y a 16 années.
GenericPortlet - how to get an ApplicationContext.
New Member Envoyer: 1 Date d'inscription: 16/02/08 Publications récentes
Hi
I'am trying to create a simple liferay portlet.
I've defined some Spring beans in WEB-INF\applicationContext.xml file.
The processAction method of my ExampleGenericPortlet needs to acces portlet application context to get the beans defined in WEB-INF\applicationContext.xml.
However PortletContext interface doesn't offer an access to ServletContext (it hasn't getServletContext() method).
so I can't do:
PortletContext portletContext = this.getPortletContext();
ServletContext servletContext = portletContext.getServletContext();
ApplicationContext ctx = WebApplicationContextUtils
.getWebApplicationContext(servletContext);
What should I do to get an application context in liferay portlet ?
PS: I've also tried casting portletContext to PortletContextImpl (that has getServletContext() method) but it causes ClassCastException.
Regards
JohnB
I'am trying to create a simple liferay portlet.
I've defined some Spring beans in WEB-INF\applicationContext.xml file.
The processAction method of my ExampleGenericPortlet needs to acces portlet application context to get the beans defined in WEB-INF\applicationContext.xml.
However PortletContext interface doesn't offer an access to ServletContext (it hasn't getServletContext() method).
so I can't do:
PortletContext portletContext = this.getPortletContext();
ServletContext servletContext = portletContext.getServletContext();
ApplicationContext ctx = WebApplicationContextUtils
.getWebApplicationContext(servletContext);
What should I do to get an application context in liferay portlet ?
PS: I've also tried casting portletContext to PortletContextImpl (that has getServletContext() method) but it causes ClassCastException.
Regards
JohnB
Dennis Kieselhorst, modifié il y a 16 années.
RE: GenericPortlet - how to get an ApplicationContext.
New Member Publications: 10 Date d'inscription: 18/02/08 Publications récentes
Hi,
try PortletApplicationContextUtils.
Regards
Dennis
try PortletApplicationContextUtils.
Regards
Dennis
Seungpil Lee, modifié il y a 14 années.
RE: GenericPortlet - how to get an ApplicationContext.
New Member Envoyer: 1 Date d'inscription: 14/08/09 Publications récentes
Try this one...
PortletContext pc = this.getPortletContext();
ApplicationContext context = PortletApplicationContextUtils.getWebApplicationContext(pc);
Service service = (Service) context.getBean("bean-name");
You may need spring-webmvc-portlet.jar file...
PortletContext pc = this.getPortletContext();
ApplicationContext context = PortletApplicationContextUtils.getWebApplicationContext(pc);
Service service = (Service) context.getBean("bean-name");
You may need spring-webmvc-portlet.jar file...
Fairouz F, modifié il y a 13 années.
RE: GenericPortlet - how to get an ApplicationContext.
Junior Member Publications: 52 Date d'inscription: 03/02/11 Publications récentes
I'am trying to create a simple liferay portlet with spring+hibernate+JSF.
I've defined some Spring beans in WEB-INF\applicationContext-hibernate.xml file.
I have used this method to get the beans defined in WEB-INF\applicationContext-hibernate
.xml.
This is my code:
package web.common;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import org.springframework.context.ApplicationContext;
Hi
import org.springframework.web.context.support.WebApplicationContextUtils;
public class ServiceFinder {
public static Object findBean(String beanName){
FacesContext context= FacesContext.getCurrentInstance();
ServletContext servletContext =
(ServletContext)context.getExternalContext().getContext();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
Object o =appContext.getBean(beanName);
return o;
}
}
But,I have an error:
ERROR [PortletServlet:96] javax.portlet.PortletException: org.apache.jasper.JasperException: java.lang.IllegalStateException: Il est interdit d''utiliser clear() quand la taille de tampon== 0
-I don't understand the message of error!!
Can someone help me,please?
I've defined some Spring beans in WEB-INF\applicationContext-hibernate.xml file.
I have used this method to get the beans defined in WEB-INF\applicationContext-hibernate
.xml.
This is my code:
package web.common;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import org.springframework.context.ApplicationContext;
Hi
import org.springframework.web.context.support.WebApplicationContextUtils;
public class ServiceFinder {
public static Object findBean(String beanName){
FacesContext context= FacesContext.getCurrentInstance();
ServletContext servletContext =
(ServletContext)context.getExternalContext().getContext();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
Object o =appContext.getBean(beanName);
return o;
}
}
But,I have an error:
ERROR [PortletServlet:96] javax.portlet.PortletException: org.apache.jasper.JasperException: java.lang.IllegalStateException: Il est interdit d''utiliser clear() quand la taille de tampon== 0
-I don't understand the message of error!!
Can someone help me,please?