• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Portlet Communication: What is application scope, anyway?

 
gunslinger & author
Posts: 169
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 <portlet:DefineObjects/> doesn't have a smiley in the middle ]
[ November 22, 2005: Message edited by: Jessica Sant ]
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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.
 
Popeye has his spinach. I have this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic