Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

getting PortletSession in faces portlet

57 views
Skip to first unread message

Suji

unread,
Sep 4, 2008, 9:30:00 AM9/4/08
to
Hi I have a requirement to set an attribute in PortletSession in JSF portlet.
How can I get portletSession instance in PageCodeBase ?
I tried,
PortletRequest portletRequest=(PortletRequest)getFacesContext().getExternalContext().getRequest();
PortletSession session = portletRequest.getPortletSession();

In this line : portletRequest=(PortletRequest)getFacesContext().getExternalContext().getRequest();
But the Object we are getting here can not be Type casted to Portlet request. So its throwing exception.

Is there any way to get PortletSession in in PageCodeBase?

-Thanks in advance

Jim Barnes

unread,
Sep 4, 2008, 1:08:15 PM9/4/08
to
try this
com.ibm.faces.portlet.httpbridge.PortletRequestWrapper request =
(PortletRequestWrapper)FacesContext.getCurrentInstance().getExternalContext().getRequest();
javax.portlet.PortletRequest prequest = request.getPortletRequest();

IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0

IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0

The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM

Suji

unread,
Sep 5, 2008, 1:23:34 AM9/5/08
to
does this wrapperRequestClass supported in portal server version 5.1? I am using 5.1 version, here I could not find find this package com.ibm.faces.portlet.httpbridge.
Please suggest how could I get Portletsession in 5.1 version server.

Jim Barnes

unread,
Sep 5, 2008, 6:59:16 AM9/5/08
to
what version of rad are you using to develop the code?

Suji

unread,
Sep 5, 2008, 7:21:27 AM9/5/08
to
hi Jim,
I am using RAD 6.0.1.
your help is appreciated in getting PortletSession in this environment
PortlaSever5.1 RAD 6.0.1

Jim Barnes

unread,
Sep 5, 2008, 7:23:55 AM9/5/08
to
with the rad 6.0 jars what you had should work, this is what was given to me by the Rad team

PortletRequest request = (PortletRequest)FacesContext.
getCurrentInstance().getExternalContext().getRequest();

Suji

unread,
Sep 5, 2008, 7:46:58 AM9/5/08
to
When I tried this

PortletRequest request = (PortletRequest)FacesContext.
getCurrentInstance().getExternalContext().getRequest();
my portlet is not getting displaed. It says portlet not available.

But when I type cast it to HttpServletRequest, the portlet is getting displayed.
i.e HttpServletRequest request = (HttpServletRequest )FacesContext.
getCurrentInstance().getExternalContext().getRequest();

So I guess, the request object we are getting from external context cant be type casted to PortletRequest.

I am stuck up here to get portletSession, since I need to communicate the change done in one page(portlet) has to be communicated to another page (another portlet).

Any solution for this is highly appreciated.
Thanks

Jim Barnes

unread,
Sep 5, 2008, 8:03:06 AM9/5/08
to
it should I would suggest opening a ticket with the rad team

Suji

unread,
Sep 22, 2008, 8:30:05 AM9/22/08
to
hi
I am using RAD 6.0 and portal server V 5.1
I have found 2 types of portlet projects we can create
1)Portlet Project
2)Portlet Project(JSR 168)

I have created faces portlets by these 2 options
When I created the faces portlet using first option, I was getting class cast exception
PortletRequest = (PortletRequest) facesContext.getExternalContext().getRequest();

But when I created faces portlet using second option I was able to type cast the request into Portlet Request.

So what is the difference between these two kind of project
Portlet Project and Portlet Project(JSR 168)

Jim Barnes

unread,
Sep 22, 2008, 8:39:29 AM9/22/08
to
the first one uses the IBm API which is a deprecated API

Suji

unread,
Sep 22, 2008, 8:50:25 AM9/22/08
to
Thanks Jim,
I am working on existing project which was created by first option i.e deprecated IBM API.
Now I want to share some information between the faces portlet.
Since I am not getting PortletSession(because not getting PortletRequest from facesContext). is there any alternative that I can share the information between the portlets?

I tried HttpSession also, the attributes in the HttpSession is also not shared among portlets.

Your suggestion is helpful..

Jim Barnes

unread,
Sep 22, 2008, 8:53:48 AM9/22/08
to

yurykats

unread,
Sep 22, 2008, 9:33:48 AM9/22/08
to
Two things.

First, you can get portlet request using the API you qouted in both cases, however if you are using a legacy portlet, not JSR168, PortletRequest would be a different class in a different package, so I presume you are casting it to the wrong class.

Second, you don't even need the request object to get to the session in JSF. You can get the session straight from the External Context:
FacesContext.getCurrentInstance().getExternalContent().getSessionMap()

Suji

unread,
Sep 22, 2008, 10:54:23 AM9/22/08
to
thanks,
Ya you are right, in the deprecated IBM API, I could able to get PortletRequest when I type casted to "org.apache.jetspeed.portlet.PortletRequest". and able to get "org.apache.jetspeed.portlet.PortletSession" from this request.

However this session is not shared between the portlets, as we can acheive in JSR 168 by mentioning (APPLICATION_SCOPE).

the second point you mentioned getting sessionscoped Map by "FacesContext.getCurrentInstance().getExternalContent().getSessionMap()" also doesnt shared between portlet.

Jim has provided the link that we could achieve this by creating PortletService.
Can we acheive the sharing of information between the portlets by using existing API?

0 new messages