Share data between portlet and sevlet
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > WebSphere > WebSphere Portal Server > Share data between portlet and sevlet




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Share data between portlet and sevlet  


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-24-05 11:14 PM

Hi!
I want to set session variables in a JSR 168 portlet and read these variable
s 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 servl
et 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





[ Post a follow-up to this message ]



    Re: Share data between portlet and sevlet  


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-28-05 09:50 PM

I know if from your portlet you place an item in the session using PORTLET_S
COPE, 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 th
is.

HttpSession session = request.getSession(false);
String storedAttrName = javax.portlet.PortletSessionUtil.decodeAttributeName
("foo");
session.getAttribute(storedAttrName);





[ Post a follow-up to this message ]



    Re: Share data between portlet and sevlet  
George Daswani


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Sponsored Links  




 





   All times are GMT. The time now is 05:44 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register