• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
pkarre kumar
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic