10-28-05 10:49 PM
Even if you use APPLICATION_SOPE, your servlet won't automatically be able
to retreieve the values using the same keys..
PortletSessions are stored in the HttpSession but they are namespaced (even
when it's set to APPLICATION_SCOPE I believe).
One test you can do is to call a servlet in the same WAR file (as your
portlet) then Iterate through the HttpSession, you'll notice that
name/values are there, but the keys are namespaced.
IMHO, there are two ways to approach this problem - one is by retrieving the
Internal Handle to the HttpServletRequest (pluto specific, works on IBM
WebSphere 5.1)
eq..
public void processAction(ActionRequest request, ActionResponse response)
23;
PortletSession ps = request.getPortletSession();
HttpSession hs =
((org.apache.pluto.core.impl.PortletSessionImpl)ps).getHttpSession();
// save something to the portlet session globally for all portlets,
namespaced when accessed via servlets on the same war
ps.setAttribute("someKey", someObject,
PortletSession.APPLICATION_SCOPE);
// no namespacing going on here, servlets on the same war can access the
variable simply by using the same key name
hs.setAttribute ("someKey", someObject);
}
The above definitely works on pluto, and IBM WPS 5.1.X specific, and only
works if the servlet is in the same WAR file as the portlet..
Now, if you want to share the attributes from portlets -> servlets in
different WAR files, then you'll have to use some sort of distributed
caching product like coherence, or for something less powerful that's
already available in the environment, WAS Dynamic Cache which should be
available in WAS 5.1.X bundled w/ the portal server
[url]http://publib-b.boulder.ibm.com/Redbooks.nsf/RedbookAbstracts/tips0435.html?Open[/
url]
I'll try to write an example based on WAS DynaCache and will post it in my
blog if time permits.
<jroets@auragen.com> wrote in message
news:669268993.1130529111858.JavaMail.wassrvr@ltsgwas007.sby.ibm.com...
>I know if from your portlet you place an item in the session using
>PORTLET_SCOPE, you can use the code below in your servlet to get the item
>back out of the session. I'm not sure about how using APPLICATION_SCOPE
>would affect this.
>
> HttpSession session = request.getSession(false);
> String storedAttrName =
> javax.portlet.PortletSessionUtil.decodeAttributeName("foo");
> session.getAttribute(storedAttrName);
[ Post a follow-up to this message ]
|