Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

The Portlet Packet: Inter-portlet communication in Portlet 2.0

Add dynamic interaction to your portal applications

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

The Portlet 1.0 spec didn't do much to enable portlets to communicate, especially if they lived in different Web applications. Author Naresh Devnani shows you how all that has changed with the new Portlet 2.0 spec, with a new event model that makes it easier for portlets to talk -- and listen. Level: Intermediate

Portlet 2.0 is the recently finalized latest version of the Java portlet specification. One of the shortcomings of the previous version of the spec (JSR168) was lack of support for inter-portlet communication. As a result, developers tasked with presenting dynamic interaction on Web portals had to resort to all kinds of fancy workarounds.

The Portlet Packet: 3-for-1

This article is about the new inter-portlet communication facilities found in Portlet 2.0. See these other articles in the JavaWorld Portlet Packet to round out your education -- and look for future articles, too!

The Portlet 2.0 specification is designed to fill this gap with a revamped event model that allows portlets to publish and subscribe to events from other portlets. This article will explain the event model and walk you through some sample portlets that use this model to communicate.

Before you begin this article, you should already have some knowledge of portal programming. This article is intended for intermediate developers familiar with portlet development using the Portlet 1.0 spec, who want to learn about inter-portlet communication in Portlet 2.0.

The Portlet 2.0 event model

The portlet event model is a loosely coupled, brokered model that allows a portlet to react to state changes without direct user action with that portlet. These state changes may be generated from the container or from other portlets.

You could exchange information between portlets through portlet sessions in Portlet 1.0, but all those portlets would have to be part of same portlet application. With events, you can exchange information between portlets, even when they are not part of the same application. This is good, as enterprises use portlets from different sources (different vendors, for instance, or different development teams), and it becomes hard to contain them within same portlet application.

Examples and source code

In this article the Portlet 2.0 event model is introduced using a two sample Portlet 2.0 applications. The first application, jsrsample, has an event class that is created by a publishing portlet and consumed by a subscriber portlet. The second application, jsrsample2, only consumes the event created by jsrsample's publish portlet. You can download the source for these applications anytime.

Events are not only used for portlet-to-portlet communication; the portlet container can also raise events that can be consumed by portlets. The Portlet 2.0 specification has some pre-defined container events, such as newWindowState and newPortletMode.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comments (1)
Login
Forgot your account info?

This article provides good starting point for event model...By Anonymous on February 19, 2009, 5:30 amThis article provides good starting point for event model...

Reply | Read entire comment

View all comments

Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources

More from JavaWorld