This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic