This document was uploaded by user and they confirmed that they have the permission to share
it. If you are author or own the copyright of this book, please report to us by using this DMCA
report form. Report DMCA
Overview
Download & View A Well Behaved Portlets as PDF for free.
A well-behaved Jetspeed portlet Design and construct a Jetspeed portlet that plays well with others By Bob Fleischman, JavaWorld.com, 11/29/04 Jetspeed 2.0 is scheduled for release in early 2005. However, that hardly means that there is no more interest in Jetspeed 1.x. Jetspeed, the open source portal venture from the Jakarta Project, has been around for several years and is in use around the world. This article presents a working example of how to construct a Jetspeed portlet that runs efficiently, adheres to the Model 2 architecture, and, by not interfering with additional portlets, plays well with others. In addition, I demonstrate some simple ways to improve performance and point out the mistakes that can cost you days of debugging time. Before I go any further, let's get the prerequisites out of the way. This article's example is based upon Jetspeed 1.5 and has been tested with a development version of Jetspeed 1.6, which has not been finalized. Please note: This example is not compliant with Java Specification Request 168. JSR 168 is at the heart of Jetspeed 2.0 and is beyond this article's scope. However, a subsequent article will demonstrate how to recast this portlet to comply with Jetspeed 2.0. This article's code is compiled with Java 1.4.2. I run Jetspeed on Tomcat 5.x; although the latest of version of Tomcat 4.x will probably function just as well. The HTML and JavaScript have been tested with both Internet Explorer and Firefox. In addition, I assume the reader is familiar with Jetspeed, has Maven installed, and has tried the simple Jetspeed tutorials.
Before we get started Writing portlets is almost like writing servlets, and, in fact, can conform to the Model 2 architecture. However, portlets must function as part of a larger framework, both in terms of operations and the HTML page; therefore, it is critically important that early in your design, you consider the possibility that your portlet might collide with other portlets on the page. For example, if two different portlets both have a JavaScript function called "Submit_Form()", the page will generate a JavaScript error and neither portlet will function. An intranet portal, such as Jetspeed, allows multiple instances of the same portlet on a page, with each assigned a unique portlet ID. Attributes of one instance can be changed without affecting the siblings, if everything is coded correctly. For example, suppose a portlet allows a user to change the background color. If that portlet appears three times on a portal page, a change in one of the Hiren
1
instances' background colors should not affect the other instances—unless, by design, we want them to change. However, without exercising care in coding the view and the controllers, it is easy to confuse attributes and thus display incorrect data. Local data needs to be kept local. This same portlet example exposes another potential problem on the generated HTML page: when the Change Color button is pressed on the first instance, how do we ensure that the JavaScript and the action controller for the second instance are not fired? The opposite of local data is shared data. Imagine a portlet where all instances display the same data and appear identical—for example, a Telephone List portlet. Changing the help-desk phone number in one instance of the portlet should be reflected in all instances. Decide early whether your portlet requires either a local or shared data model. This article's example portlet uses a local data model. (A follow-up article will demonstrate shared data and database access.)