 | Level: Intermediate Ying Chun Guo (guoyingc@cn.ibm.com), Software Engineer, IBM Mary Taylor (marytaylor@us.ibm.com), Senior Software Engineer,
IBM
21 Jun 2007 This article is the eighth in a series that addresses the development of
Composite Business Services (CBSs). CBSs provide the capability to integrate
existing technologies and products to reflect desirable business intentions, such as
configurability. IBM WebSphere® Portlet Factory is a portlet creation environment
that simplifies and accelerates the development, deployment, maintenance, and re-use
of portlets. This article introduces how to use WebSphere Portlet Factory to achieve
configurability within the presentation layer by using dynamic profiles.
Introduction
The dynamic profiling capability of WebSphere Portlet Factory helps developers to
create multiple, highly customized applications from one code base. Using the
dynamic profiling capability, you can define variables in a common profile
set
that can be configured by multiple tenants in a shared environment. The multiple
applications are created by applying those configured profiles to the portlets to
change the appearance, content, and behavior of the portlet. In this article, you
see an extension of the multi-tenant scenario first described in Part
1.
In this Part 8, you learn how to implement, manage, and specify WebSphere Portlet Factory
profiles for multiple tenants in a composite application for banking. The article
concludes with a comparison of the dynamic profiling configuration capabilities
to the basic configuration capabilities portlets provide.
Defining the scenario
The dynamic profile capabilities are demonstrated using the Jivaro banking
use case that is depicted in Figure 1.
Figure 1. Jivaro use case
The scenario actors are:
- Bank Provider Operations Administrator: an administrator who has the
capability to configure the bank profiles for Jivaro Bank.
- Bank Administrator: the administrator for each hosted bank that has the capability
to perform account operations through Web pages.
- Bank Customers: customers of the hosted banks who have the capability to view
their account information through Web pages.
The account object is the subject of this scenario. The scenario illustrates
how two banks hosted in the Jivaro environment, Bank1 and Bank2, can customize the
appearance of the common account object displayed in the portals of each bank.
Implementing the
scenario
WebSphere Portlet Factory runtime runs in the portal server as a common dynamic
Web application. In this scenario, a profile is configured for each bank that
WebSphere Portlet Factory uses to generate different unique portlets. When bank
customers log into their banks, the corresponding profiles for their banks are
selected by portal servers to feed the parameters to the portals. Figure 2 shows that the Web pages on the left and right
are two different Web pages that are generated by different profiles based on the
same code. Notice that the labels and the optional values are different. Bank 001
labels the sixth field as Account Name, while Bank 002 labels the sixth field as Branch.
In the Account Type field, Bank 001 provides two selections (savings or checking) and
Bank 002 provides three fields (savings, checking, and external).
The portlet at the top of Figure 2 shows the configuration
capability to the Banking Provider Operations Administrator.
Figure 2. Profile mechanism
Begin by creating the portlets for Bank1 and Bank2 using WebSphere Portlet
Factory. This involves creating the SubscriberAccount Portlet used by the bank
administrator to manage account information in his bank, and it involves using the
UserAccountsView Portlet used by the bank customer to view his account
information. After that, you can implement the dynamic profiles needed to customize
the portlets, which is documented in the following sections.
Step 1: Profile the
portlets
The profiling activity involves three steps:
- Create a profile set using the Profile Set Manager in WebSphere Portlet
Factory Designer. A profile set is a container that stores a set of parameters
used by the profiles associated with the profile set. For the example, create a profile set named “J2BWPFportletsConfigPS” and add profile
entries that represent basic attributes of banks, endpoints of Web services,
and advanced configuration parameters, such as the show/hide status of
fields.
- Create a profile for each bank. Create two profiles named bank1 and bank2.
- Set the parameter values in the profiles. Details follow in the next sections.
Tip: In order to ensure several portlets can use the same profile set,
integrate them in the same WebSphere Portlet Factory project. All the models in
the same WebSphere Portlet Factory project can share the same profile set.
Step 1a: Profile
basic attributes
In Jivaro Bank, each bank has a unique identifier and a name. These basic
attributes need to be set up as configurable parameters.
- Open the Variable builder named bankId.
- Click the profile mechanism icon
beside Initial Value.
- At the Profile Input prompt, select
J2BWPFportletsConfigPS as the Profile
Set Name and select bankId as Profile Entry Name (see
Figure 3).
- Edit the entry values. Set 001 to bank1 profile, and set 002 to bank2 profile.
- Click OK.
Figure 3. Profile variable
bankId
Step 1b: Profile
endpoints of Web services
Web service endpoints can vary among tenants. The endpoints need to be specified
as parameters.
- Open a Web Service Call builder, and click
Advanced
to open advanced inputs.
- Click the profile mechanism icon
beside Service URL (override).
- At the Profile Input prompt, select
J2BWPFportletsConfigPS as the Profile
Set Name, and select accountQueryWithoutSelectorEP as the Profile Entry Name
(see Figure 4).
- Edit the entry value of profile bank1 and profile bank2.
- Click OK.
Figure 4. Profile service endpoint
Step 1c: Profile
show/hide status
AccountName and Description are desired fields for Bank1 but not for Bank2.
Show/Hide status is the setting that enables this behavior.
- Open the Data Column Modifier builder that is used in the Add Account Web
page. Make sure the check box beside Manage Columns is checked.
- Click the profile mechanism icon
to the left of the AccountName row in the column table.
- At the Profile Row of Inputs prompt, click the profile mechanism icon beside Status (see Figure 5).
- At the Profile Input prompt, select
J2BWPFportletsConfigPS as the Profile
Set Name, and select account_AccountName_Enable as the Profile Entry Name
(see Figure 6).
- Edit entry values, set Show to bank1 profile, and set Hide to bank2 profile.
- Click OK.
Figure 5. Profile row
Figure 6. Profile show/hide status
Step 1d: Profile
field description
WebSphere Portlet Factory provides the functionality to configure the description
of a field. The description of AccountName is an example.
- Open the Data Column Modifier builder that is used in the add account Web page.
Make sure the check box beside Manage Columns is checked.
- Click the profile mechanism icon
to the left of the row AccountName in the column table.
- When you see the Profile Row of Inputs prompt, click the profile mechanism icon beside Column Heading (see Figure
5).
- At the Profile Input prompt, select
J2BWPFportletsConfigPS as the Profile
Set Name, and select account_AccountName as the
Profile Entry Name (see Figure 7).
- Edit entry values: set Account Name to bank1 profile, and set Branch to bank2
profile.
- Click OK.
Figure 7. Profile field
description
Step 1e: Profile
values of optional list
The optional values of a field can also be configured. AccountType is an
example.
- Add a Data Field Modifier builder to the model.
- Set the input Field Selector Tool to
Select By
Name, and set the input fields to the name of AccountType in Data Page.
- Set the input Field Behavior to
Data Entry. Set the input Content Type
to Select. Set the input Enumeration Options to Specify Below (see Figure 8).
- Click the profile mechanism icon
beside Select Data. A Profile Input prompt appears. Select
J2BWPFportletsConfigPS as the Profile Set Name, and select
account_accountType as the Profile Entry Name (see
Figure 9).
- Edit entry values: set SAVINGS,CHECKINGS to the bank1 profile, and set
SAVINGS, CHECKINGS, EXTERNAL to the bank2 profile.
- Click OK.
Figure 8. Data field modifier
builder
Figure 9. Profile values of
optional list
Step 2: Create a portlet
for configuration
In this section, you create a portlet to manage the profile entry values for
the profile set J2BWPFportletsConfigPS, which you created in
Step 1. WebSphere Portlet Factory provides a suite of APIs to
create, update, and delete profiles. Using these APIs, you can create a portlet to
expose the values you want to be customizable, and you provide a user interface to
set these values.
Step 2a: Add
customizable variables
Values of profile entries are shown and updated through Web pages. To enable
this, you need to create variables for storing the name of selected profiles and the
values of profile entries. You already created a string variable called SelectedProfile
for the selected profile name. In order to keep a simple map between variables and
the profiles entries, name the variables using a prefix pfvar_ concatenated
to the name of the profile entry. Some sample variables are shown in
Figure 10.
Figure 10. Sample variables
Step 2b: Develop a
helper class using profiling APIs
Figure 11 shows the main classes and methods for profiling.
Use ProfileSetStorageManager to get a profile set by the name, and save a
profile set. Use ProfileSet to get its profiles. Use Profile and
ProfileValue to get the values of profile entries.
Figure 11. Profiling API
Using these APIs, a helper class is created to implement the following functions
(see com.ibm.J2B.wpf.profile.ProfileCustomizeHelper in WPFPortlets.zip).
- Getting a list of profiles from the profile set (see method
getProfiles)
- Getting values of profile entries of a profile, and setting them to variables
in Web applications (see method getVariables)
- Getting the updated values of profile entries from HttpServletRequest, and
saving them to profile set (see method saveProfile).
Step 2c: Add portlet
controls
In this step, you add controls to the configuration portlet to handle the
variables and invoke the functions.
- Add a linked Java™ object, and set the class name to be the helper
class.
- Use an html table to edit the page layout. The name of the <span>
tag must be same as the variable name (see Listing 1).
- Add a Select builder onto tag SelectedProfile. Set Select Data to be the
return of method getProfiles, and set Selected Values to be the variable
SelectedProfile.
- Add an HTML Event Action Builder, specifying to invoke the getVariables method
when the selected profile is changed.
- Add HTML controls (such as Select and Text Input) to other named tags to
display profile entries. Specify the values to be the corresponding variables.
- Add a submit button, and specify to invoke saveProfile method when the button
is clicked.
Listing 1.
HTML code
<body>
<form name="myForm" method="post">
<table>
<tr>
<td> Profile: </td>
<td> <span name="SelectedProfile"></span> </td>
</tr>
<tr>
<td> BankId: </td>
<td><span name="pfvar_bankId"></span></td>
</tr>
<tr>
<td> BankName: </td>
<td><span name="pfvar_bankName"></span></td>
</tr>
<tr>
<td><span name="submitbutton"></span></td>
<td></td>
</tr>
</table>
</form>
</body>
|
Step 3: Create a custom
Profile Selection Handler
When there are multiple profiles within a profile set, the profile selection
handler determines which profile should be used. There are several predefined
handlers in WebSphere Portlet Factory, such as Explicit Handler and J2EE Role
Handler. You can define your own selection handler. In this scenario, you can define a
simple custom profile selection handler that associates a separate profile for
each bank.
Step 3a: Implement a
handler class
The SelectionHandler class implements the ProfileSelection interface, which has a
method selectProfile(). This method selects a Profile from the specified
ProfileSet that is passed in and returns its name. The source code of the handler
class is shown in Listing 2.
Listing 2. Source code of the handler class
public class BankUserSelectorHandler extends SelectionHandlerBase {
public String selectProfile(HttpServletRequest request,
ProfileSet profileSet, String modelName, String explicitProfile,
ModelInstanceCreator modelInstanceCreator) {
String userid = "";
try {
userid = request.getRemoteUser();
int index = userid.indexOf('@');
if (index == -1) return ProfileSet.DEFAULT;
String domain = userid.substring(index + 1);
return domain;
} catch (Exception e) {}
return ProfileSet.DEFAULT;
}
}
|
Step 3b: Create a
handler definition
The handler definition is an XML file that lists the Java classes used to
implement the profile selection handler and properties of the profile selection
handler. All handler definitions are stored in the
WEB-INF/config/selection_handlers directory. The handler definition file
in the example scenario is shown in Listing 3.
Listing 3.
Handler definition file
<Handler name="J2BBankProfileSelectionHandler">
<Description>Handler for J2B WPF portlet</Description>
<Selection class="com.ibm.J2B.wpf.handler.BankUserSelectorHandler" />
</Handler>
|
Step 3c: Set the
profile selection handler for the profile set
After creating the custom profile selection handler, set this selection handler
for the profile set J2BWPFportletsConfigPS.
- Double-click WEB-INF/profiles/J2BWPFportletsConfigPS profile set to
open it.
- In the Select Handler tab, choose the selection handlers you created from the
Profile Selection Handler select box (see Figure 12).
- Save the profile set.
Figure 12. Set the profile
selection handler
Comparing with a
non-WebSphere Portlet Factory solution
The configure mode of portlets also provides configurability. But the parameters
in portlet configure mode and the function scope are only related to one portlet.
For parameters that are shared among several portlets, such as bank id, bank name,
and common Web services’ endpoints, they need to be configured in each portlet.
With WebSphere Portlet Factory dynamic profiles, you can develop a centralized
portlet to provide a configuration user interface. The shared parameters need
to be set only once, which decreases the workload and possibility of error.
Without WebSphere Portlet Factory, the configuration of portlets is implemented
by JSP and Java code. You get the values of configuration parameters through a Java
API. More complicated code is needed to provide more advanced configuration, such as configuring
the hide/show status of a field or configuring the optional values in a drop-down
list. With WebSphere Portlet Factory
dynamic profiles, configuration of Web applications becomes very easy and powerful,
providing configuration capability without writing code.
Although WebSphere Portlet Factory provides these advantages, there are no
what-you-see-is-what-you-get (WYSWYG)
tools for the development of WebSphere Portlet Factory, as there are for JSP and
HTML. WebSphere Portlet Factory provides wizard-like builders, which are more
abstract than WYSWYG tools. Using meaningful builder names is very important in
portlet development with WebSphere Portlet Factory.
Conclusion
This article described how to implement a configurable user interface
using WebSphere Portlet Factory dynamic profiles. Profiling is a very robust
WebSphere Portlet Factory feature. A profile contains a set of parameters
(name/value pairs) that drive the generation of customized portlets. Using
profiles, you can automatically generate different variations of a portlet from
the same model for different users or situations. The steps you followed involved
profiling the portlet, creating a portlet to configure profile entry values,
creating a custom profile selection handler, and associating the profile set with
this selection handler. While the same functionality can be created by writing
code, WebSphere Portlet Factory provides a set of builders that enable the
implementation of this function without writing code.
Download | Description | Name | Size | Download method |
|---|
| Source code of this article | wpfportlets.zip | 340KB | HTTP |
|---|
Resources Learn
Get products and technologies
- Innovate your next
development project with
IBM trial software,
available for download or on DVD.
Discuss
About the authors  | 
|  | Ying Chun Guo works as a software engineer at the China Technology Institute, China Software Development Laboratory. She is currently working on composite business services (CBS) and Service-Oriented Architecture (SOA). |
 | 
|  | Mary Taylor is a senior software engineer. She is working in the Strategic Technology Architecture and Incubation team, and she is currently working on an SOA CBS pilot. Her interests include DB2 and DataStage. |
Rate this page
|  |