214 IBM Workplace Forms: Guide to Building and Integrating a Sample Workplace Forms Application
6.3 Writing a portlet
In this section we make an assumption that the reader has good knowledge about portlet
development. The goal is not to demonstrate the end-to-end process of portlet creation,
rather, it is to give an overview of the process flow of information in the portlet.
To begin writing a portlet, you need an application development tool such as WebSphere
Studio Application Developer (WSAD) or the Rational Application Developer (RAD). For this
example we used RAD, and the steps identified below will have a RAD context.
When create a new project using RAD, you will find that a number of files are automatically
added to the project, for example, the
portlet.xml file. You will also need to create some
additional files, including some JSPs and Java files, all of which will be explained next.
portlet.xml
This file is used to store the configuration information about the portlet. It is essentially a
properties file. When you initialize the portlet, this file is read to set the attributes of the portlet.
These attributes are saved in memory so that they can be called at anytime in the code.
The attributes that we set in this file contain the paths to the directories on the file system
where we store the forms that the users will process. You will notice that we use both an
absolute path to the directories, and a relative path. For example, the absolute path to the
directory that the user is pointed to when they click on the New Orders button is
C:\\Redpaper_Demo\\Form_Templates, and the relative path is
/wpfredpaper/forms/Form_Templates/.
The reason we need both paths is that when you call the method reading the file system in
the Java file, you need an absolute path in order for it to be recognized as a directory,
whereas once the JSP that is launched to render the contents of the directory, it needs a
relative path to render correctly. (Refer to Example 6-1 for the coding.)
Example 6-1 portlet.xml contents
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE portlet-app-def PUBLIC "-//IBM//DTD Portlet Application 1.1//EN"
"portlet_1.1.dtd">
<portlet-app-def>
<portlet-app uid="wpfredpaper.WPFRedPaperPortlet.477c98c6a0" major-version="1"
minor-version="0">
<portlet-app-name>WPFRedPaper application</portlet-app-name>
Note: This portlet example is a complicated one due to the fact that we took an existing
J2EE application and rewrote it to fit the
WebSphere Portal environment. Not everything
that we do in this example is required to display a form in the Portal. We will also highlight
an easier way to create a portlet that displays a form.
Important: You need to manually create the following file directories on the WebSphere
Portal’s file system:
C:\Redpaper_Demo\Form_Templates
C:\Redpaper_Demo\Sales_Rep_Forms
C:\Redpaper_Demo\Manager_Forms
C:\Redpaper_Demo\Director_Forms
C:\Redpaper_Demo\Approved_Forms
C:\Redpaper_Demo\Cancelled_Forms