<<

. 48
( 87 .)



>>

ployed on a remote Portal system. This is different than executing the port-
let in the test environment. The preview function works only with external
Portal systems, not an installed WebSphere Portal for a test environment. It
does not set up a debugging environment. Instead the portlet application
is deployed on the remote Portal system using the XML con¬guration in-
terface of Portal. The portlet is put on a preview page and Studio™s internal
Web browser opens that portal page.
P1: FCH/SPH P2: FCH/SPH QC: FCH/SPH T1: FCH
WY009-15 WY009-BenNatan-v1.cls May 11, 2004 14:50




WebSphere Portlet Development Environment 283


Building the Portlet Application WAR File
A portlet application project is a J2EE-compliant Web application. You can
easily build a deployable WAR ¬le for your portlet application simply by
using the Export utility in Studio. Similarly, you can import resources from
a WAR ¬le to your portlet application project using the Import function.


Creating the Poll Portlet Project
In this section you will create the portlet application project in Studio for
our sample portlet application. This section assumes that you have already
installed the Portlet Toolkit in Studio. If the Portal Toolkit is not already
installed, follow the instructions that came with the toolkit (either down-
loaded from the Web site mentioned earlier or obtained from the Portal
product CD) to run the toolkit.
The intention of this chapter is to introduce the Portlet development
toolkit in the context of creating our example portlet application. This chap-
ter is not intended as a tutorial on WebSphere Studio itself. The discussion
here assumes you have a familiarity with Studio, its key concepts, and
how to navigate the workbench. If you do not have experience using Web-
Sphere Studio you may want to review the product help content, which has
excellent information about the development environment and includes
scenario-based tutorials.


The Portlet Perspective
First let™s take a look at the portlet perspective in Studio (see Figure 15-7).
Start WebSphere Studio and open the portlet perspective from the Window
item on the menu bar.
The default perspective shows a number of views and an editor. The
key views to consider are the Project Navigator view, the editor, and the
tasks view. These will be used initially as you create the portlet project.
The Palette view, Attributes view, and Quick Edit view are used primarily
with the Page Designer editor when editing JSP or HTML ¬les. Change to
the Tasks view by selecting the Tasks tab on the bottom of the view with
Quick Edit.
Create a portlet project for our Poll Portlet by selecting New ➪ Portlet
Application Project from the File menu item in the Studio toolbar. This
opens the Portlet Project creation wizard (see Figure 15-8).
Enter the name of your portal project. Choose Poll for this example. The
project location speci¬es the directory where the project ¬les will be created.
You may change the directory using the Browse button, but the selected
P1: FCH/SPH P2: FCH/SPH QC: FCH/SPH T1: FCH
WY009-15 WY009-BenNatan-v1.cls May 11, 2004 14:50




284 Chapter 15




Figure 15-7 Portlet perspective in Studio.


directory must be empty. You can select to create either an empty portlet or
a basic portlet.
An Empty Portlet creates a portlet project directory structure and the Web
and portlet deployment descriptors. The wizard sets the Java build path
for the project, including the required jar ¬les for the portlet API. The port-
let deployment descriptor that is created de¬nes a portlet application and a
single portlet in that application. You can add additional portlets to the port-
let application by re-executing the wizard and specifying a portlet instead
of a portlet application.
A Basic Portlet generation performs this function also but in addition gen-
erates source code for the portlet. The code generated will depend on the
options selected in the wizard. At a minimum, a portlet class is created
that extends PortletAdapter and implements a doView() method that
invokes a sample JSP. Since the portlet class is created the deployment de-
scriptors created can reference that class. This step is useful as both the Web
descriptor references this as the servlet class for the Web application and
the portlet class name is used in both descriptors. Create the Poll portlet
using the Basic Portlet type.
P1: FCH/SPH P2: FCH/SPH QC: FCH/SPH T1: FCH
WY009-15 WY009-BenNatan-v1.cls May 11, 2004 14:50




WebSphere Portlet Development Environment 285




Figure 15-8 Portlet Project creation wizard.


After selecting Create Basic Portlet, select Con¬gure Advanced Options
and then Next. On the next page of the wizard you can specify the name
of the Enterprise Application (EAR) project (see Figure 15-9). Since portlet
applications are packaged and deployed to portal through a WAR ¬le, the
EAR ¬le selected here will not affect that deployment. However, the EAR
will be used for portlet deployment to the WebSphere Portal test environ-
ment. You may want to put portlet applications in separate EAR projects
to be able to manage more easily the portlets that are executing in the test
environment. This project being created is set, and can be modi¬ed later, in
the EAR deployment descriptor. For this example portlet, leave the project
set as the default EAR.
J2EE supports multiple Web applications running in the same server in-
stance. The context root is a unique (within the server instance) identi¬er
P1: FCH/SPH P2: FCH/SPH QC: FCH/SPH T1: FCH
WY009-15 WY009-BenNatan-v1.cls May 11, 2004 14:50




286 Chapter 15




Figure 15-9 Enterprise Application project settings.


to ensure that an HTTP request reaches the correct Web application. The
context root is a path identi¬er used in the URI immediately following the
host name. The default value de¬ned in the Studio wizard is the project
name. This value is set, and can be modi¬ed later, in the EAR deployment
descriptor with the Web module de¬nition. For this example portlet use the
provided default value.
Also on this page you can specify the J2EE level of the Portal into which
you expect to deploy this portlet. WebSphere Portal 5.0 supports J2EE level
1.3. Select J2EE 1.3 for your example portlet and click Next.
The next page in the wizard gathers the ¬nal set of information needed
for the portlet and Web deployment descriptors (see Figure 15-10). Here
you specify the name of the portlet and the name of the portlet application.
Also, you specify the default locale and the portlet title in the language of
the default locale. Change these to values of your choice.
P1: FCH/SPH P2: FCH/SPH QC: FCH/SPH T1: FCH
WY009-15 WY009-BenNatan-v1.cls May 11, 2004 14:50




WebSphere Portlet Development Environment 287




Figure 15-10 Specifying portlet settings.



Select Change Code Generation Options. The package pre¬x is the pack-
age name that will be created in this new project and it is the package that
will be referenced in the Web deployment descriptor for the servlet class
name. Change the package pre¬x to a package name of your choice. The
class pre¬x will be used as the class name for the portlet class and also ref-
erenced in the Web deployment descriptor as the servlet class name (with
the package pre¬x). A version of this package name will also be used to
create a directory structure in the Poll Portlet project for other generated
¬les such as JSP ¬les. The default class pre¬x name is ¬ne for our portlet,
so click Next.
The ¬nal three pages in the wizard are used to determine what source code
¬les to generate. This next page speci¬es portlet event handling options.
Most portlets will have a requirement to implement an action event listener.
P1: FCH/SPH P2: FCH/SPH QC: FCH/SPH T1: FCH
WY009-15 WY009-BenNatan-v1.cls May 11, 2004 14:50




288 Chapter 15




Figure 15-11 Event handling options.


This preselected choice will generate an actionPerformed() method in
the portlet class and also modify that class de¬nition to implement the
ActionListener interface.
This selection will also generate a simple view bean and a simple session
bean. The form bean has a getter and setter method for an instance variable
to hold a portlet URI string. The session bean provides similar function for
a text string. An example JSP using these beans will also be created.
Cooperative portlets are portlets that interact by sharing data elements
through a broker mechanism that handles portlet requests to declare, pub-
lish, and share properties (see Figure 15-11). A portlet associates actions
with properties that get invoked when the property change is received.
Selecting all three of these Cooperative Portlet options will generate a sim-
ple example of two cooperative portlets, their JSP ¬les, and a control WSDL
¬le. Selecting Enable Click-to-Action Target generates a control WSDL ¬le so
the target portlet can receive properties (select Add Form Sample to ensure
P1: FCH/SPH P2: FCH/SPH QC: FCH/SPH T1: FCH
WY009-15 WY009-BenNatan-v1.cls May 11, 2004 14:50




WebSphere Portlet Development Environment 289


a complete working example). Selecting Add Click-to-Action Sender Portlet
Sample creates a simple property sender portlet. Selecting Enable Click-to-
Action source updates the source portlet JSP to use the Click-to-Action tag
library to publish properties. These options are available only for J2EE 1.3
applications.
Portlets that reside on the same portal page can communicate during
the action processing phase using message events. Selecting these options
updates the portlet class de¬nition to implement the MessageListener
interface and the messageReceived() method. You can choose to gener-
ate a sample portlet to send a broadcast message.
Finally, on this page you can select to generate code in the sample portlet
to record action events in session so that they can be displayed later. Leave
this page with the default values and select Next.
The next page allows you to generate sample code to handle user cre-
dentials that are managed through the Credential Vault (see Figure 15-12).




Figure 15-12 Credential Vault options.
P1: FCH/SPH P2: FCH/SPH QC: FCH/SPH T1: FCH
WY009-15 WY009-BenNatan-v1.cls May 11, 2004 14:50




290 Chapter 15




Figure 15-13 Markup and portlet mode options.



The Credential Vault is a secure store for user secrets and provides a portlet
service to manage the vault and its contents and handle authentication to
back-end applications.
Selecting options on this page will generate sample code to access cre-
dentials from the Credential Vault. There are several options to support
credentials of various scopes. Leave this option unchecked and select Next.
The last page of the wizard allows you to modify the portlet deployment
descriptor to support multiple markups and additional portlet modes (see
Figure 15-13). In addition, when the markup options are selected, device-
speci¬c JSP ¬les will be generated. The portlet will invoke the correct JSP
depending on the client request type. Leave these options unchecked and
select Finish.
P1: FCH/SPH P2: FCH/SPH QC: FCH/SPH T1: FCH
WY009-15 WY009-BenNatan-v1.cls May 11, 2004 14:50




WebSphere Portlet Development Environment 291




Figure 15-14 Poll project created.

<<

. 48
( 87 .)



>>