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
Chapter 6. Integrating with Portal 215
<portlet id="wpfredpaper.WPFRedPaperPortlet"
href="WEB-INF/web.xml#wpfredpaper.WPFRedPaperPortlet" major-version="1" minor-version="0">
<portlet-name>Display Workplace Form Portlet</portlet-name>
<cache>
<expires>0</expires>
<shared>no</shared>
</cache>
<allows>
<maximized/>
<minimized/>
</allows>
<supports>
<markup name="html">
<view />
</markup>
</supports>
</portlet>
<portlet id="wpfredpaper.WPFRedPaperPortletC2ASender"
href="WEB-INF/web.xml#wpfredpaper.WPFRedPaperPortletC2ASender" major-version="1"
minor-version="0">
<portlet-name>Select Workplace Form Portlet</portlet-name>
<cache>
<expires>0</expires>
<shared>no</shared>
</cache>
<allows>
<maximized />
<minimized />
</allows>
<supports>
<markup name="html">
<view />
</markup>
</supports>
</portlet>
</portlet-app>
<concrete-portlet-app uid="wpfredpaper.WPFRedPaperPortlet.477c98c6a0.1">
<portlet-app-name>WPFRedPaper application</portlet-app-name>
<concrete-portlet href="#wpfredpaper.WPFRedPaperPortlet">
<portlet-name>Display Workplace Form Portlet</portlet-name>
<default-locale>en</default-locale>
<language locale="en">
<title>WPFRedPaper portlet</title>
<title-short></title-short>
<description></description>
<keywords></keywords>
</language>
<config-param>
<param-name>c2a-action-descriptor</param-name>
<param-value>/wpfredpaper/wsdl/WPFRedPaperPortletC2A.wsdl</param-value>
</config-param>
<config-param>
<param-name>c2a-nls-file</param-name>
<param-value>wpfredpaper.nls.WPFRedPaperPortletC2A</param-value>
</config-param>
</concrete-portlet>
</concrete-portlet-app>
<concrete-portlet-app uid="wpfredpaper.WPFRedPaperPortletC2ASender.477c98c6a0.1">
216 IBM Workplace Forms: Guide to Building and Integrating a Sample Workplace Forms Application
<portlet-app-name>WPFRedPaper application (Click-to-Action
sender)</portlet-app-name>
<concrete-portlet href="#wpfredpaper.WPFRedPaperPortletC2ASender">
<portlet-name>Select Workplace Form Portlet</portlet-name>
<default-locale>en</default-locale>
<language locale="en">
<title>WPFRedPaper portlet (Click-to-Action sender)</title>
<title-short></title-short>
<description></description>
<keywords></keywords>
</language>
<config-param>
<param-name>TEMPLATE_FOLDER</param-name>
<param-value>C:\\Redpaper_Demo\\Form_Templates</param-value>
</config-param>
<config-param>
<param-name>MANAGER_FOLDER</param-name>
<param-value>C:\\Redpaper_Demo\\Manager_Forms</param-value>
</config-param>
<config-param>
<param-name>DIRECTOR_FOLDER</param-name>
<param-value>C:\\Redpaper_Demo\\Director_Forms</param-value>
</config-param>
<config-param>
<param-name>APPROVED_FOLDER</param-name>
<param-value>C:\\Redpaper_Demo\\Approved_Forms</param-value>
</config-param>
<config-param>
<param-name>SALES_REP_FOLDER</param-name>
<param-value>C:\\Redpaper_Demo\\Sales_Rep_Forms</param-value>
</config-param>
<config-param>
<param-name>CANCELLED_FOLDER</param-name>
<param-value>C:\\Redpaper_Demo\\Cancelled_Forms</param-value>
</config-param>
<config-param>
<param-name>TEMPLATE_FOLDER_RELATIVE</param-name>
<param-value>/wpfredpaper/forms/Form_Templates/</param-value>
</config-param>
<config-param>
<param-name>MANAGER_FOLDER_RELATIVE</param-name>
<param-value>/wpfredpaper/forms/Manager_Forms/</param-value>
</config-param>
<config-param>
<param-name>DIRECTOR_FOLDER_RELATIVE</param-name>
<param-value>/wpfredpaper/forms/Director_Forms/</param-value>
</config-param>
<config-param>
<param-name>APPROVED_FOLDER_RELATIVE</param-name>
<param-value>/wpfredpaper/forms/Approved_Forms/</param-value>
</config-param>
<config-param>
<param-name>SALES_REP_FOLDER_RELATIVE</param-name>
<param-value>/wpfredpaper/forms/Sales_Rep_Forms/</param-value>
</config-param>
<config-param>
<param-name>CANCELLED_FOLDER_RELATIVE</param-name>
<param-value>/wpfredpaper/forms/Cancelled_Forms/</param-value>
</config-param>

Get IBM Workplace Forms: Guide to Building and Integrating a Sample Workplace Forms Application now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.