Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

developerWorks Community:

  • Close [x]

Building SOA composite business services, Part 8: Building multi-tenant portlets using WebSphere Portlet Factory dynamic profiles

Ying Chun Guo (guoyingc@cn.ibm.com), Software Engineer, IBM Japan, Software Group
author photo
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 (marytaylor@us.ibm.com), Senior Software Engineer, IBM
Mary Taylor photo
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.

Summary:  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.

View more content in this series

Date:  21 Jun 2007
Level:  Intermediate
Also available in:   Chinese  Korean

Activity:  8431 views
Comments:  

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
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
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:

  1. 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.

  2. Create a profile for each bank. Create two profiles named bank1 and bank2.

  3. 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.

  1. Open the Variable builder named bankId.

  2. Click the profile mechanism icon beside Initial Value.

  3. At the Profile Input prompt, select J2BWPFportletsConfigPS as the Profile Set Name and select bankId as Profile Entry Name (see Figure 3).

  4. Edit the entry values. Set 001 to bank1 profile, and set 002 to bank2 profile.

  5. Click OK.

Figure 3. Profile variable bankId
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.

  1. Open a Web Service Call builder, and click Advanced to open advanced inputs.

  2. Click the profile mechanism icon beside Service URL (override).

  3. At the Profile Input prompt, select J2BWPFportletsConfigPS as the Profile Set Name, and select accountQueryWithoutSelectorEP as the Profile Entry Name (see Figure 4).

  4. Edit the entry value of profile bank1 and profile bank2.

  5. Click OK.

Figure 4. Profile service endpoint
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.

  1. 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.

  2. Click the profile mechanism icon to the left of the AccountName row in the column table.

  3. At the Profile Row of Inputs prompt, click the profile mechanism icon beside Status (see Figure 5).

  4. 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).

  5. Edit entry values, set Show to bank1 profile, and set Hide to bank2 profile.

  6. Click OK.

Figure 5. Profile row
Profile row

Figure 6. Profile show/hide status
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.

  1. 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.

  2. Click the profile mechanism icon to the left of the row AccountName in the column table.

  3. When you see the Profile Row of Inputs prompt, click the profile mechanism icon beside Column Heading (see Figure 5).

  4. At the Profile Input prompt, select J2BWPFportletsConfigPS as the Profile Set Name, and select account_AccountName as the Profile Entry Name (see Figure 7).

  5. Edit entry values: set Account Name to bank1 profile, and set Branch to bank2 profile.

  6. Click OK.

Figure 7. Profile field description
Profile field description

Step 1e: Profile values of optional list

The optional values of a field can also be configured. AccountType is an example.

  1. Add a Data Field Modifier builder to the model.

  2. Set the input Field Selector Tool to Select By Name, and set the input fields to the name of AccountType in Data Page.

  3. 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).

  4. 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).

  5. Edit entry values: set SAVINGS,CHECKINGS to the bank1 profile, and set SAVINGS, CHECKINGS, EXTERNAL to the bank2 profile.

  6. Click OK.

Figure 8. Data field modifier builder
Data field modifier builder

Figure 9. Profile values of optional list
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
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
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.

  1. Add a linked Java™ object, and set the class name to be the helper class.

  2. 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).

  3. 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.
  4. Add an HTML Event Action Builder, specifying to invoke the getVariables method when the selected profile is changed.

  5. 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.

  6. 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.

  1. Double-click WEB-INF/profiles/J2BWPFportletsConfigPS profile set to open it.

  2. In the Select Handler tab, choose the selection handlers you created from the Profile Selection Handler select box (see Figure 12).

  3. Save the profile set.

Figure 12. Set the profile selection handler
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

DescriptionNameSizeDownload method
Source code of this articlewpfportlets.zip340KBHTTP

Information about download methods


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

author photo

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 photo

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.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=SOA and Web services, WebSphere
ArticleID=232072
ArticleTitle=Building SOA composite business services, Part 8: Building multi-tenant portlets using WebSphere Portlet Factory dynamic profiles
publish-date=06212007
author1-email=guoyingc@cn.ibm.com
author1-email-cc=
author2-email=marytaylor@us.ibm.com
author2-email-cc=flanders@us.ibm.com