WebSphere Portal Server - Sharing data between portlets and servlets

This is Interesting: Free IT Magazines  
Home > Archive > WebSphere Portal Server > May 2004 > Sharing data between portlets and servlets





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Sharing data between portlets and servlets
Bryan Hogan

2004-05-20, 5:36 pm

Is there a simple and clean way to share data between a portlet and servlet
using WPS 5.0.2 API.

Our particular scenario is as follows:
- PortletA stores information into the PortletSession
- PortletA renders JSP/HTML containing an <IMG> or <EMBED> tag that
references ServletB. ServletB is included in the same web application.
- ServletB requires PortletA session information in order to properly
complete

Q: How can ServletB access session information stored by PortletA?

I see that the PortletSession interface for JSR 168 allows the developer to
specify a "scope" when setting and getting attributes from the session. The
WPS version of PortletSession does not currently include this feature.

I also see that the PortletSessionImpl classes include a method named
'getHttpSession()' which will return the base HttpSession. Storing shared
information into the base HttpSession would solve our problem; however, we
would prefer not make hardcoded references to the implementation class in
our code.

I suspect that others have encountered this issue. What is the best way to
deal with it?


Thanks,
Bryan Hogan



Brian Lalor

2004-05-21, 5:39 pm

Bryan Hogan wrote:

> I also see that the PortletSessionImpl classes include a method named
> 'getHttpSession()' which will return the base HttpSession. Storing shared
> information into the base HttpSession would solve our problem; however, we
> would prefer not make hardcoded references to the implementation class in
> our code.


That's either broken, or I don't understand it. When you use
getHttpSession(), you *do* get an HttpSession object, but the keys
stored in the object are prefixed with what is probably the unique id of
the portlet application (not sure about that, but it sure isn't what I
put in there). For example, if you do
getHttpSession().setAttribute("foo", "bar")
when you iterate through getHttpSession().getAttributes() you see
something like "7_A_3_foo".

> I suspect that others have encountered this issue. What is the best way to
> deal with it?


I used a single bean for sharing information between the portlet and the
servlet. Then, in the servlet, I iterated through all values in the
session and matched the class against the class of the bean. Not
terribly elegant, but it did work...

B
Jon Mell

2004-05-22, 5:37 am

You can try using the servlet context. Michael Harris had posted some info
on how to use this earlier.

Jon

"Bryan Hogan" <bryanh@nospam.ibm.com.zzz> wrote in message
news:c8j4lf$5d24$1@news.boulder.ibm.com...
> Is there a simple and clean way to share data between a portlet and

servlet
> using WPS 5.0.2 API.
>
> Our particular scenario is as follows:
> - PortletA stores information into the PortletSession
> - PortletA renders JSP/HTML containing an <IMG> or <EMBED> tag that
> references ServletB. ServletB is included in the same web application.
> - ServletB requires PortletA session information in order to properly
> complete
>
> Q: How can ServletB access session information stored by PortletA?
>
> I see that the PortletSession interface for JSR 168 allows the developer

to
> specify a "scope" when setting and getting attributes from the session.

The
> WPS version of PortletSession does not currently include this feature.
>
> I also see that the PortletSessionImpl classes include a method named
> 'getHttpSession()' which will return the base HttpSession. Storing shared
> information into the base HttpSession would solve our problem; however, we
> would prefer not make hardcoded references to the implementation class in
> our code.
>
> I suspect that others have encountered this issue. What is the best way

to
> deal with it?
>
>
> Thanks,
> Bryan Hogan
>
>
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com