aspose file tools*
The moose likes Portals and Portlets and the fly likes Liferay Portal 6.0.5 portletfaces-bridge-2.0.0-BETA2.jar-JSF 2.0 Spring Session Creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "Liferay Portal 6.0.5 portletfaces-bridge-2.0.0-BETA2.jar-JSF 2.0 Spring Session Creation" Watch "Liferay Portal 6.0.5 portletfaces-bridge-2.0.0-BETA2.jar-JSF 2.0 Spring Session Creation" New topic
Author

Liferay Portal 6.0.5 portletfaces-bridge-2.0.0-BETA2.jar-JSF 2.0 Spring Session Creation

pkarre kumar
Greenhorn

Joined: Feb 22, 2011
Posts: 2
Hi friends,

I am new to Liferay+JSF(2.0)+portletfaces. we are using xhtml as view. how can I create a session object in xhtml(or in backing beans if..) and how can I access same session object in another xhtml/bean object?
I tried like this in backing bean..
public void logout(ActionEvent av)
{
/*String elExpression = "#{session}";
ELContext elContext = FacesContext.getCurrentInstance().getELContext();
ValueExpression valueExpression = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(
elContext, elExpression, PortletSessionImpl.class);
PortletSessionImpl pSession = (PortletSessionImpl) valueExpression.getValue(elContext);
System.out.println("session id :-> "+ pSession.getId());*/


try {

HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpSession session = request.getSession(true);
session.setAttribute("name", "myname");
System.out.println("Mybbeanclass.logout() : "+(String)session.getAttribute("name"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
==
I am getting error like
com.liferay.portlet.ActionRequestImpl cannot be cast to javax.servlet.http.HttpServletRequest
com.liferay.portlet.PortletSession cannot be cast to com.liferay.portlet.PortletSession (Commented code)

Thank you in advance.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Portlets use the portlet equivalent to request and response, although it also depends on the phase (action, event, render)
Therefore you would use (most likely ) RenderRequest rather than HttpRequest, and you would use that to get a PortletSession rather than an HttpSession.
Keep in mind that the PortletSession stores state for the portlet and cannot usually be used outside that portlet.

If you want portlets to share state (excluding IPC) you can
1) use PortletUtils to access the underlying HttpRequest and HttpSession
2) use the PortletSession and set data to be application scoped and set private-session-attributes to false in the liferay-portlet.xml or
3) use the PortletSession and set data to be application scoped and prefix the name with LIFERAY_SHARED_ eg LIFERAY_SHARED_myState
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Liferay Portal 6.0.5 portletfaces-bridge-2.0.0-BETA2.jar-JSF 2.0 Spring Session Creation