aspose file tools*
The moose likes Portals and Portlets and the fly likes Portlet Communication: What is application scope, anyway? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "Portlet Communication: What is application scope, anyway?" Watch "Portlet Communication: What is application scope, anyway?" New topic
Author

Portlet Communication: What is application scope, anyway?

Kenneth A. Kousen
gunslinger & author
Ranch Hand

Joined: Sep 18, 2002
Posts: 89
    
    5
Hi all,

There is a way to get JSR 168 portlets in the same portlet application to communicate with each other. As others have said (see http://www.jroller.com/page/RickHigh?entry=jsr_168_inter_portlet_communication especially for details), if one portlet puts an object in the portlet session at "application scope," then another portlet in the same portlet application can access that variable.

For example, here's some code from a trivial example rigged up in RAD6:

From the View JSP in the first portlet:

From the first portlet code:

From the View JSP in the second portlet (please forgive the use of scriptlets -- it's just to keep things simple):

This actually seems to work, as long as the two portlets are in the same portlet application. Even more, opening a second browser doesn't appear to interact with the first session at all, which is good.

My question is, if PortletSession.APPLICATION_SCOPE looks like session scope and acts like session scope, why not just call it session scope? I can't tell you how much time I wasted looking for a mechanism to do interportlet communication (wires, click-to-action, etc.) when there was one there all along.

Thanks,

Ken Kousen

[ Jess added UBB [ code ] tags to preserve whitespace, and disabled smilies so the <portletefineObjects/> doesn't have a smiley in the middle ]
[ November 22, 2005: Message edited by: Jessica Sant ]

Kenneth A. Kousen, Ph.D. (assorted certs), President, Kousen IT, Inc.
Author of Making Java Groovy - http://www.kousenit.com
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

[KAK]
This actually seems to work, as long as the two portlets are in the same portlet application. Even more, opening a second browser doesn't appear to interact with the first session at all, which is good.

AFAIK, This will depend on which browser and how you open it.
In IE, if you hit "Ctrl+N" to open a new browser -- you'll share the same session as the original browser window. If instead you open a new browser by clicking on the IE icon a second time, you'll get a different sessino than the original browser window.

In opera, if you open a new tab, you'll share the same session. I'm not sure if you open a new window.

But some experimnetation will help you to figure out how each browser shares its cookies.

[KAK]
My question is, if PortletSession.APPLICATION_SCOPE looks like session scope and acts like session scope, why not just call it session scope? I can't tell you how much time I wasted looking for a mechanism to do interportlet communication (wires, click-to-action, etc.) when there was one there all along.

I took a portal class a couple weeks ago and remember asking myself the same question. It seems kind of silly. But Yes, PorletSession.APPLICATION_SCOPE == request.getSession() (the servlet Session scope). The naming could have been made more obvious IMHO.

One thing I think you need to keep in mind with this method... is what if you have 2 instances of the same portlet. Say a weather portlet that shows the weather for Philadelphia, and another that shows the weather for Salt Lake City. If the weather portlet is trying to communicate to the news portlet -- you'll get a bit of a write-write-read problem when each weather portlet tries to write to the same PortletSession.APPLICATION_SCOPE variable, and the news portlet will get the value from whoever wrote to it last.


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Portlet Communication: What is application scope, anyway?
 
Similar Threads
Show details of story on a different page of portlet
How to pass session data between 2 Portlets???
Not able to send data from one struts portlet to another struts portlet
Portlet Data sharing using liferay and icefaces
get the paramaters from one jspportlet into another portlet