WebSphere Portal Server - Share data between portlet and sevlet

This is Interesting: Free IT Magazines  
Home > Archive > WebSphere Portal Server > October 2005 > Share data between portlet and sevlet





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 Share data between portlet and sevlet

2005-10-24, 6:14 pm

Hi!
I want to set session variables in a JSR 168 portlet and read these variables in a servlet (default.jsp). I have tried to set variables with APPLICATION_SCOPE in the portlet, but when I read these in the HttpSession in the servlet they are decoded and the
refore not useful. is there a way to achive this?
I am running Websphere Portal 5.1.
Regards
/Björn

2005-10-28, 4:50 pm

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);
George Daswani

2005-10-28, 5: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){

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

http://publib-b.boulder.ibm.com/Red...s0435.html?Open

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);



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com