Skip to main content

IBM WebSphere Developer Technical Journal: Integrating WebSphere Portal and WebSphere Personalization -- Part 2

Building a Personalized Portlet Using WebSphere Portal content publishing V4.2

Bruce Olson (bolson@us.ibm.com), member of the WebSphere Enablement team, Raleigh
Bruce R. Olson is a member of the WebSphere Enablement team in Raleigh. Bruce has worked as a consultant on WebSphere products since 1999, specializing in Personalization, content publishing, and WebSphere Portal. Before joining the WebSphere team, he helped to design and implement the IBM C++ User Interface Class Library and coauthored two editions of Power GUI Programming. Before that, Bruce worked in the IBM Artificial Intelligence Support Center, working with Expert Systems.
Venkata (Vishy) Gadepalli (vgadepal@us.ibm.com), member of the WebSphere Enablement team, Raleigh
Venkata V. (Vishy) Gadepalli is a member of the WebSphere Enablement team in Raleigh. He has over five years experience in the IT field. His current area of expertise is enabling and consulting for WebSphere products, specializing in WebSphere Application Server, Portal, and Personalization. Before joining the Enablement team, Vishy was a member of the WebSphere development team.

Summary:  This article describes how to build a personalized portlet on WebSphere Portal V4.2 platform. New features of V4.2 as well as best practices based on a new approach for building personlized portlets are pointed out along the way.

Date:  02 Jun 2003
Level:  Introductory
Activity:  319 views

Introduction

This article is Part 2 in a series addressing various topics related to using WebSphere® Personalization with WebSphere Portal.

In Part 1, we described how to create a personalized portlet using Version 4.1 of WebSphere Portal and WebSphere Personalization. In this article, we build the same personalized portlet from Part 1 on the WebSphere Portal V4.2 platform. Many changes to the personalization component in terms of the interface, packaging, and usage were made in this new release. This article will point out these differences as we build the portlet. There are also several steps in the process where we have changed our approach to emphasize best practices in building personalized portlets.

In the first article, we included lots of personalization overview information, such as explaining the different types of rules, etc. that we don't repeat here. It may be a good idea to browse through Part 1 if you're not familiar with the basic concepts of personalization, as implemented in WebSphere. In addition, more details about personalization and portals can be found in the References section at the end of this article.

In the download ZIP file, we have included the necessary files to build the database tables used in this example, as well as the final portlet for those who would prefer to browse the source and experiment with the developed portlet.


Prerequisites

To build the example in this article, you must have the following software installed on your system; it is important that you have exactly the same software versions on your machine as described here:

  • DB2© Universal Database, Version 7.2 and fixpack 7
  • HTTP Server, Version 1.3.19.3
  • WebSphere Application Server, Advanced Edition, Version 4.0.4
  • WebSphere Studio Application Developer, Version 4.0.3 (hereafter called Application Developer)
  • WebSphere Portal content publishing wizards for Application Developer Version 4.0
  • WebSphere Portal Server 4.2
  • WebSphere Portal content publishing 4.2
  • WebSphere Portal Toolkit for Application Developer

The code we have provided assumes that you are using IBM Directory Server V4.1 for your LDAP Server. We have also provided code you can use if you are using Lotus Domino Server 5.0.10 for authentication. We recommend that you use the WebSphere Portal Setup Manager to install the software.


Steps to create the personalized portlet

The steps you must take to create the personalized portlet are listed below.

To create this sample, complete the following steps:

  1. Create a JDBC Driver and data source
  2. Create a portlet project in Application Developer
  3. Create the user and content resources
  4. Create a content spot for the rules
  5. Add the content spots to the JSP file
  6. Add code to the JSP to populate the content spots
  7. Export the portlet WAR file from Application Developer
  8. Deploy the portlet in WebSphere Portal
  9. Create the WPCP project
  10. Create the personalization rules
  11. Associate the rules with the content spots
  12. Publish the WPCP project
  13. Translate the LDAP user ID
  14. Test the portlet

The characteristics of the portlet we will build in our example include:

  • The portlet we will build simulates a simple banking news application.
  • The model consists of two simple tables, Customer and Customernews. All of the user data is defined by and stored in the Customer table. The content model store is the Customernews table.
  • Visitors to the site are classified based on the balance in their bank accounts.

1. Create a JDBC Driver and data source

In our first article, we let the personalization user and content resource wizards create a data source for us; however, we would rather utilize the full capabilities of the connection pool model. Instead of creating a unique data source for each resource, the best practice is to define a data source in the WebSphere Application Server Administrator Console and have each resource use it by specifying its JNDI name in the DataSource field in the WPCP wizard.Follow these steps to create the JDBC Driver and Data Source:

  1. Start the Websphere Application Server Administrator's Console.
  2. Select Console => New => JDBC Provider....
  3. On the "JDBC Provider Properties" dialog, select the General tab, and enter values for the Name and Description fields, as shown in Figure 1. When finished, click on the ... box (to the right of the Implementation class field).
    Figure 1.JDBC Provider Properties
    JDBC Provider properties
  4. Since we are using local DB2, select the first line, as shown in Figure 2, then select OK.
    Figure 2. Selecting the Implementation Class
    Selecting the Implementation Class
  5. Select the Nodes tab on the "JDBC Provider Properties" dialog, then select Install New....
  6. Select your node in the "Install Driver" window (Figure 3), then select Specify Driver....
    Figure 3. Install Driver window
    Install Driver window
  7. On the "Specify the Driver Files" dialog, click the Add Driver... button to display a dialog from which you can select the proper DB2 driver.
  8. Navigate to and select the db2java.zip file, and select Open.You will find this file where you installed DB2, for example in the SQLLIB\java directory.
  9. Highlight the file and click the Set button, as shown in Figure 4.
    Figure 4. Setting the Driver file
    Setting the Driver file
  10. Now, back on the "Install Driver" window (Figure 3), select the Install button to install the driver on your node.
  11. Finally, select OK to finish creating the JDBC driver (Figure 5).
    Figure 5. Completing the JDBC Provider Properties window
    Completing the JDBC Provider Properties window
  12. Right-click on Data Sources and select New....
    Figure 6. Creating the Data Source
    Creating the Data Source
  13. Enter the following values for the fields in the "Data Source Properties" dialog, as shown in Figure 7.
    FieldValue
    NamePersSampleDatasource
    JNDI namejdbc/jdbcdb2SAMPLE (the name we used when creating our resources)
    databaseNameSAMPLE
    userwsdemo
    passwordwsdemo1

    Figure 7. Data Source Properties window
    Data Source Properties window
  14. Select Test Connection to ensure that you have entered everything correctly. Once you have verified the data source is working, select OK.

2. Create a portlet project in Application Developer

The next major task is to create a project for the portlet in Application Developer.

The WebSphere Portal Toolkit provides a wizard that will create a project for any of the common portlet types. This wizard is extremely useful because it generates all of the required files such as portlet.xml and web.xml, adds the required JAR files, and sets up the build classpaths and environment for you in the correct directory structure. This convenience allows you to focus on writing the actual portlet code without having to worry about all of the infrastructure.

  1. To launch Application Developer:
    1. Select Start => Programs => IBM WebSphere Studio Application Developer => IBM WebSphere Studio Application Developer.
    2. Select Perspective => Open => Other to launch the "Select Perspective" window.
    3. In this window, select Portlet and then OK.
    You are now ready to create a portlet project.
  2. From the Application Developer tool bar, select File => New => Portlet application project to launch the "Create a Portlet project" wizard.
  3. Ensure that Use default location is selected, then enter the following values, as shown in Figure 8. When finished, select Next.
    FieldValue
    Project namePersSamplePortlet
    Enterprise Application project namePersSamplePortletEAR
    Context root/wps/PersSamplePortlet

    Figure 8. Create a Portlet project dialog
    Create a Portlet project dialog
  4. On the next screen, select the Basic Portlet radio button, and select Next. The "Create a Portlet project - Basic portlet parameters" dialog opens.
  5. Enter the following values for these fields, as shown in Figure 9. Accept the defaults for the remaining fields. When finished, select Next.
    FieldValue
    Concrete portlet titlePersSamplePortlet
    Portlet class nameMyPersSamplePortlet
    Context root/wps/PersSamplePortlet

    Figure 9 Basic portlet parameters dialog
    Basic portlet parameters dialog
  6. In the Navigator view, examine the project that you just created. You should see two folders named PersSamplePortletEar and PersSamplePortlet, with a directory structure that resembles Figure 10.
    Figure 10. Portlet project directory structure
    Portlet project directory structure

3. Create the user and content resources

Next, create the personalization resources using the WPCP wizards in Application Developer.

Every personalized portlet must have a user resource and one or more content resources. The user resource describes attributes of the user currently logged into WebSphere Portal. The content resources describe attributes of the content that you want to personalize. This information is used by personalization rules to match the right content with the right user. The wizards give you the ability to easily create the most common types of resources. For users, this information is most often found in either LDAP or a relational database. If it is in a database, each row describes a user and each column contains an attribute of that user. Content that you want to personalize is often also found in relational databases, where each row represents a piece of content, and each column holds an attribute describing that content. The wizards support those scenarios. In cases where the user information (or content) is not stored in a location supported by the wizards, you can write your own resource by implementing a set of Java classes.

3.1 Make sure the WPCP wizards are available

If you do not see the content spot or the Content and User Resource wizards in the Application Developer toolbar (see Figure 11 to see what the icons look like), you can add them:

  1. Select Perspective => Customize.
  2. Expand the Other folder.
  3. Select the WebSphere Portal content publishing toolbar check box, then OK.

3.2 Create the user resource

The Application Developer wizards for WPCP in WebSphere Portal Version 4.2 are significantly different (and improved) from those that shipped with Version 4.1.We will point out some of the major differences as we go along.

If you're familiar with the previous version, the first thing that you will notice in the new version is that the old User Resource and Content wizards have been combined into one wizard, named the Content and User Resource wizard. Another improvement is that the wizard knows the correct place in the folder structure in which to create the resources. (In the previous release, the resource was created in whatever folder you highlighted when invoking the wizard.)

To create the User Resource using the new wizard:

  1. Select the WPCP Content and User Resource wizard icon, as shown in Figure 11.
    Figure 11. Launching the Content and User Resource wizard
    Launching the Content and User Resource wizard
  2. On the first screen of the wizard, select the Web users radio button, leave all other defaults, then select Next.
  3. In the "Database Connection" dialog, enter the following values for these fields, as shown in Figure 12. When finished, select Connect to Database.
    FieldValue
    Connection namePersSampleConnection
    User IDwsdemo
    Passwordwsdemo1
    Database vendor typeselect DB2 UDB V7.2

    Figure 12. Database Connection
    Database Connection page
  4. When the connection completes successfully, a new set of tabs displays (Figure 13).
  5. From the Available Tables list on the left, select the CUSTOMER table. This is the primary table for the user resource. Add it to the Selected tables list by pressing the > button.
    Figure 13. Tables
    Tables page
  6. Select Next to go to the Columns tab.
  7. Click the >> button on the "Columns" window to select all of columns in this table. If this table had many columns, you would want to be selective about which columns you pick. Select only if you need to write rules that use a particular column's values in deciding which rows should be part of the result set, or need to display the column as part of the rows in the result set.
  8. Next, select the Deployment tab (Figure 14).There are several interesting things to note about this page.The biggest change in this release is that you can specify a deployment environment for the resource that doesn't necessarily have to match the protocol you chose on the first page of the wizard. You must also specify the type of the WPCP Authoring repository at the bottom of the page. This is the page where you need to ensure that you specify the name of an existing Data Source so that one is not created implicitly for you.
    Figure 14. Deployment
    Deployment page
  9. Click Next to go to the "Resource Generation Options" dialog, then select Finish.
  10. As the files are being generated, the dialog shown in Figure 15 will display. Select Yes so that the project is set up as a WPCP project, with all of the appropriate JAR files in the classpath.
    Figure 15. WPCP Nature dialog
    WPCP Nature dialog

The files that are generated by the Content and User Resource wizard are highlighted in Figure 16. Notice that the source files are compiled and placed in the appropriate directory within the project by default.


Figure 16. Content and User Resource wizard output
Content and User Resource wizard output

3.3 Create the content resource

To create a content resource using the Content and User Resource wizard, complete the same steps above that you used to create a user resource. The differences are:

  1. Leave the Web Content radio button selected, which is the default.
  2. Make sure that you select the Customernews table as your content resource (Figure 13).
  3. While creating this content resource, you can take advantage of another wizard enhancement in this release: you can have the wizard automatically generate a Content Spot for this resource now, rather than running the separate Content Spot wizard later. Figure 17 shows the box to check on the "Resource Generation Options" dialog to generate the content spot, and Figure 18 shows the files that the wizard generates.
    Figure 17. Generating a Content Spot in the Content and User Resource wizard
    Generating a Content Spot in the Content and User Resource wizard

    Figure 18. Output for the content resource
    Output for the Content Resource

4. Create a content spot for the rules

Now that you have defined some resources, you can create any additional content spots you need using the WPCP Content Spot wizard. Remember that to create a content spot, you must first create resources (which you've already done) because you must define what type of content will be used to populate the content spot.

  1. In Application Developer, select the Content Spot wizard icon, shown in Figure 19.
    Figure 19. Launching the Content Spot wizard
    Launching the Content Spot wizard
  2. In the Content Spot wizard, enter the following values, as shown in Figure 20. When completed, select Finish.
    FieldValue
    PackagePersSample
    Display NamegetCurrentUserSpot
    Class NamegetCurrentUserSpot
    Return Typeselect PersSample.Customer

    Figure 20. Completing the Content Spot wizard
    Completing the Content Spot wizard
  3. The wizard generates the Java bean wrapper for the content spot. In the Navigator window, notice that a Java file for the content spot has been generated.

5. Add the content spots to the JSP file

Now, add the content spots that you created in the previous step to the View JSP file, and then add code to reference the fields in the content spots that you want displayed.

  1. In Application Developer, navigate to the View.jsp file and double-click the file to open it in the JSP Editor.
  2. Select the Design tab, and erase all of the existing content.
  3. In the Navigator pane, select getCurrentUser.class, hold the left mouse button down, drag the file to the top of the View.jsp edit window, and drop the file here.An "Attributes" window opens. Click OK to accept the default values.
  4. Complete the same steps to drag and drop getCustomernews.class on the JSP.
  5. Select the Source tab of the edit window to view the useBean tags that were generated when you dropped the content spot class files in the JSP.
  6. Change the useBean declarations as follows (notice that the closing "/" is removed from the useBean tag, and that a </useBean> tag is used instead for each of the bean declarations):

    The original declaration in your JSP page is as follows:

    <jsp:useBean class="PersSamplePortlet.getCurrentUserSpot" id="getCurrentUserSpot"/>
    <jsp:useBean class="PersSamplePortlet.getCustomernewsSpot" id="getCustomernewsSpot"/>

    Change the above lines to look like this:

    <jsp:useBean class="PersSamplePortlet.getCurrentUserSpot" id="getCurrentUserSpot">
    <% getCurrentUserSpot.setRequest(request); %>
    </jsp:useBean>

    <jsp:useBean class="PersSamplePortlet.getCustomernewsSpot"
    id="getCustomernewsSpot">
    <% getCustomernewsSpot.setRequest(request); %>
    </jsp:useBean>

    The above changes are required for every content spot that you add to a page to link to the WebSphere Personalization run time.

6. Add code to the JSP to populate the content spots

Here, you will use the JSP Editor to add two tables to the JSP. The tables will eventually be populated with content by a rule, but for now, you will associate each table with a content spot. This essentially ties a resource to each table.

6.1 Create a table to display user information

  1. Select the Design tab in the JSP Editor.
  2. Select Insert => Table to create a new table. Specify 2 rows and 1 column, and then click OK to close the dialog.
  3. Next, double-click on the table to launch its "Attributes" dialog.
  4. Select the Dynamic tab.
  5. Select the Loop check box, then enter the value of 1 for both the Start row and End row, as shown in Figure 21.
    Figure 21. Bean Attributes and Bean Property Selection dialogs
    Bean Attributes and Bean Property Selection Dialogs
  6. Select the Browse button to launch the "Bean Property Selection" dialog (also in Figure 21). Select getCurrentUserSpot.ruleContent[], then click OK.
  7. In the previous step, a resource was associated with the table. Now, you will specify which attributes or columns of the resource will be used to populate the table. Select the first row of the table and enter "You are logged in as: ".
  8. Position the cursor to the right of the text, and select Insert => Dynamic Elements => Property Display.
  9. In the "Attributes" dialog, select Browse to launch the "Bean Property Selection" dialog.
  10. This time, select the USERID attribute, and click OK on each of the dialogs to close them.
  11. Select the second row of the table, and enter "Your account balance is: ".
  12. Repeat these steps steps h through k, but this time select the Balance attribute.

6.2 Create a table to display personalized news

  1. Complete View.jsp by adding a second table to the page. Repeat steps b through e in section 6.1 Create a table to display user information above, but this time specify the value of 2 for both Start row and End row, and enter getCustomernewsSpot.ruleContent[] for Loop property field, as shown in Figure 22.
    Figure 22. Bean Property Selection dialog for the second table
    Bean Property Selection dialog for the second table
  2. When you have finished with the "Bean Property" dialog, highlight the first row of the table, and enter "Here is your personalized news...".
  3. The second row will contain the news items that are returned. In the first step, you set up a loop on this row, so there will be one row generated for each news item that is returned at run time. Highlight the second row and then select Insert => Dynamic Elements => Property Display.
  4. In the "Bean Property Selection" dialog, select the CONTENT attribute, and then click OK. See Figure 23.
    Figure 23. Selecting the content to display in the table
    Selecting the content to display in the table
  5. Save view.jsp by using CTRL-S.

7. Export the WAR file from Application Developer

By now, you have finished creating all of the WebSphere Personalization artifacts and are ready to export your portlet.

  1. In Application Developer, right-click on the PersSamplePortlet project, and select Export WAR... (Figure 24).
    Figure 24. Exporting the WAR file
    Exporting the WAR file
  2. Choose the location you want to export the WAR file to, and click Finish (Figure 25).
    Figure 25. Exporting the WAR file details
    Exporting the WAR file details

8. Deploy the portlet in WebSphere Portal

  1. To deploy the portlet on WebSphere Portal, open a browser window and enter : http://<YourFullyQualifiedHostName>/wps/myportal
  2. Log in with: user ID: wpsadmin
    password: wpsadmin
  3. To install your portlet, select the Install Portlet tab in the Portal Administration group and follow the prompts.
  4. Next, you will add the portlet to the page of your choice.Select the Edit Layout tab in the Work with Pages group.
  5. Select the page you want to install the portlet on, then click on the Add portlets icon, as shown in Figure 26.
    Figure 26. Adding a portlet to a page
    Adding a portlet to a page
  6. In the next window, enter the value Pers in the Name contains field, then select Go.
  7. Select the check box next to the name of your portlet in the Portlet title column, and then click OK (Figure 27).
    Figure 27. Selecting the portlet
    Selecting the portlet
  8. The portlet is now added to the page.Select Activate to activate the page (Figure 28).
    Figure 28. Activating the page
    Activating the page
  9. Use the Security tab in the PortalAdministration group to grant view access of your portlet to all authenticated users.

9. Create the WPCP project

Now, create a project in WPCP where you can define your rules using the personalization rule editor.

  1. To launch the WPCP, enter the following in a browser window: http://<YourFullyQualifiedHostName>/wps/wcp/index.jsp Remember to substitute the fully qualified host name for the localhost.
  2. Log in to the workspace with the following values (or whatever password you created for the wcpadmin user).: user ID: wcpadmin
    password: password
  3. From the Administration tab, select Projects/Editions, and then Add Project (Figure 29).
    Figure 29. Adding a WPCP project
    Adding a WPCP project
  4. Complete the project settings using the following table and Figure 30 as guides. (Make sure that the drive letters reflect the actual location of the software on your system):
    FieldValue
    NamePersSamplePortlet
    Context Rootwps/PersSamplePortlet

    Typically, you want this to match the context root of the Application Developer application. Since we are installing the application as a portlet, the context root we are telling you to enter will not match the context root of the portlet. (The context root of a portlet is generated dynamically when the portlet is installed, regardless of the context root you specify in the Web application.) For the purposes of this tutorial, this doesn't matter, and in a future article the context root we have you specify will turn out to be correct.
    War Root PathC:\WebSphere\Appserver\installedApps\ PersSamplePortlet_WPS_PA_801.ear\PersSamplePortlet.war

    It is very important that you look in your installedApps directory and get the exact name of the portlet EAR on your machine. The war root path is part of the dynamic classloader and is the home of the WAR from which classes will be loaded. Typically, we advise you to leave this field blank because WPCP will automatically resolve this field for you based on the context root you specify in Step 2 above. In our case, WPCP will not be able to find a Web application with the specified context root so you are entering it manually here.
    Import/Export RootC:\Program Files\WSAD\workspace\PersSamplePortlet
    Default ProcessSimplest Change Process

    We aren't doing anything with workflows but the dialog requires you to make a selection for this field.
    Version ProviderNone

    We will not be using any version control.
    Quick EditYes
    LockYes

    This article does not require you to preview the JSP page so the fields related to Preview don't need to be filled in. Preview will be covered in a future article. (It is also worth noting that Preview won't work with the specified context root.)
    Figure 30. Personalization workspace global settings
    Personalization workspace global settings
  5. Click Save to exit the dialog.

10. Create the personalization rules

We will create three types of rules:

  • Profiler rule
    We will create the UserLevel Profiler rule, which classifies the user based on the balance in theiraccount.
  • Action rules
    We will create six action rules, the first being GetCurrentUser, which gets information about the current user. The remaining five action rules get suitable news articles based on the user level.
  • Binding rule
    We will create the GetCustomerNews binding rule, which ties the Profiler and Action rules together.

When you select the WPCP Personalization tab, you will notice that the layout is just like all of the other tabs in the WPCP interface, which itself has been greatly enhanced in this release with more user friendly improvements. For example, instead of selecting the type of rule you wish to create and then performing an add, the type of rule is now just an attribute you set while editing the rule. Another nice change is that invoking the rule editor no longer launches a new window; you edit your rules in place. Perhaps the most noticeable change is that what used to be known as Classifiers and Classifications are now named Profilers and Profiles; this change was made in response to customer feedback.

Select the Rules folder to begin.

10.1 Create the UserLevel Profiler rule

  1. Click on the + button to create a new profiler rule in the rule editor (Figure 31).
    Figure 31. Invoking the Rule Editor to create a rule
    Invoking the Rule Editor to create a rule
  2. Edit the rule by entering the following values, as shown in Figure 32:
    FieldValue
    Rule NameUserLevel
    Rule TypeProfiler

    Figure 32. Editing the UserLevel Profiler
    Editing the UserLevel Profiler
  3. Click on Profile in the rule body, and name this profile Basic. Notice that the editable fields in the rule body are all hyperlinks. Simply select the hyperlinks one at a time and fill out the resulting dialogs.
  4. In the rule body, select Resource.Attribute. On the "Specify a Resource Attribute" dialog, select current Customer and Balance, as shown in Figure 33, then select Save.
    Figure 33. Selecting a resource and its attribute
    Selecting a resource and its attribute
  5. Select is equal to, and change it to is less than or equal to.
  6. Select value, and enter 100.
  7. Continue adding Profiles until the rule looks like Figure 34 below. Select add Condition when you need to add more thanone condition for a profile.
  8. Click Save when you are done.
    Figure 34. Final UserLevel Profiler rule
    Final UserLevel Profiler rule

10.2 Create the GetCurrentUser Action rule

  1. Click on the + button to create your first action rule.
  2. Edit the rule by entering the following values:
    FieldValue
    Rule NameGetCurrentUser
    Rule TypeSelect Content

    This is the most commonly used type of Action rule.
  3. Select Resource.Attribute. On the next screen, select Customer and Userid, then select Save.
  4. Select Value, and then select on the Resource Attribute radio button. Select current Customer and Userid, as shown in Figure 35. Click on Save.
    Figure 35. Specifying a value using a Resource Attribute.
    Specifying a value using a Resource Attribute
  5. Click on Save to save the finished rule.

10.3 Create the GetBasicNews Action rule

  1. Press + to create your next action rule.
  2. Name the rule GetBasicNews, repeat the steps in the previous section so that it resembles Figure 36.
    Figure 36. Final GetBasicNews
    Final GetBasicNews

10.4 Create the four remaining Action rules

Following the same steps, create the remaining four rules:

  • GetAdvantageNews
  • GetAllNews
  • GetPreferredNews
  • GetPremiumNews.

Forexample, for the GetPreferredNews rule, select the content whoselevel is set to preferred, etc.

10.5 Create the GetCustomerNews Binding rule

In this rule, you will associate the profiler rule with the actions that you created in the previous steps:

  1. Ensure that Bindings is selected in the drop-down menu for the rule types, then select + tostart the rule editor.
  2. Name the rule GetCustomerNews.
  3. When you click on Profiler, a list of available Profilers appears. Select the UserLevel Profiler (the only one we have defined).
  4. When you click on Profile, you are presented with a list ofprofiles that have been defined for the Profiler you selected in the previous step. Similarly, When you click on do Action, you get a list of all of the Actionrules that have been defined. Select do Action now.
  5. Select the Action rule that is most applicable for the profile you are working with (Figure 37). Notice that you also have the option of selecting Profilers at this point. Nesting Profilers in this way allows you to build up complex bindings when necessary.
    Figure 37. Selecting an Action
    Selecting an Action
  6. Complete the GetCustomerNews Binding rule, as shown in Figure 38.
    Figure 38. GetCustomerNews Binding rule
    GetCustomerNews Binding rule
  7. Figure 39 shows the list of rules you should have showing in the WPCP interface at this point.
    Figure 39. The final list of rules
    Final list of rules

11. Associate the rules with the content spots

Now, associate the rules you just created with the content spots that you created earlier in this exercise:

  1. Select Campaigns and Normal View in the left pane of the workspace. This displays a list of the content spots in this project. Notice that all of the entries in the Rule column are empty.
  2. Assign a rule to each of the content spots by selecting the content spot, and then clicking on the Edit button in the lower right pane (Figure 40). Select a rule from the list of rules that displays. Only rules that return the appropriate content type are listed (Figure 41).
    Figure 40. Editing the GetCurrentUser Content Spot
    Editing the GetCurrentUser Content Spot

    Figure 41. View after assigning rules to content spots
    View after assigning rules to content spots

12. Publish the WPCP project

Now that you have all of your rules defined and assigned to content spots, you can publish the project. This makes the rules available to the WebSphere Personalization run time. First you must create a Publish server, and then use it to publish the project.

  1. Select the Administration tab.
  2. Select Publish Servers, then click on the Add Server icon in the upper right pane (Figure 42).
    Figure 42. Adding a publish server
    Adding a publish server
  3. Fill in the attributes for the Publish server as follows, and as shown in Figure 43, then select Save.
    FieldValue
    Server NamePersPortletServer
    Servlet URLhttp://<YourFullyQualifiedHostName>/wps/Persadmin/publishtarget?ContextRoot= /wps/WPS_PA_801
    War Root PathC:\WebSphere\Appserver\installedApps\ PersSamplePortlet_WPS_PA_801.ear\PersSamplePortlet.war

    As mentioned in section 9. Create the WPCP project, the context root of a portlet is generated dynamically, so you again need to look for your portlet in your installedApps directory to get the correct context root. We are using the publish servlet provided by Persadmin, the WebSphere Personalization run time Web application. In this release of WPCP, there is a new option we are taking advantage of which allows you to pass a context root to the publish servlet. This context root is used by the publish servlet to determine which enterprise application the folder structure and files in WPCP should be written to. This is a nice feature, as it allows you to have multiple publish servers that publish to different locations without having to have more than one publish servlet.
    Realm User IDwpsbind
    Realm Passwordwpsbind

    Figure 43. Adding a new publish server
    Adding a new Publish server
  4. Select the Content tab.
  5. Select the Files folder, then click on the Publish icon (Figure 44).
    Figure 44. Publishing the project
    Publishing the project
  6. Select the PersPortletServer publish server and click on the right arrow icon to move it to the right pane. Click on the Publish button.
    Figure 45. Selecting the publish server
    Selecting the publish server
  7. Figure 46 shows the output you should expect to see. Make sure that you see your rules show up as "published".
    Figure 46. Output from the publish
    Output from the publish

13. Translate the LDAP user ID

In our first article we had you make some minor modifications to the User Resource java files generated by the Application Developer wizards. This step is necessary only when using WebSphere Personalization with WebSphere Portal, with security enabled. When you use WebSphere Personalization outside of WebSphere Portal, it is your responsibility to tell the WebSphere Personalization run time who the current user is by setting pzn.userName in the personalization context. However, when security is enabled, the WebSphere Personalization run time does not use pzn.UserName. Instead, the user name is obtained from the Application Server's security context. This value contains the user's DN and the application server information. For example, the name will be of the format:

user:blueagave.raleigh.ibm.com:389/uid=user1,cn=users, dc=raleigh,dc=ibm,dc=com

To identify the current user, the WebSphere Personalization run time simply needs the user ID, which in this case is user1. Therefore, you need to strip out all of the extra information or the WebSphere Personalization run time will never get a match for the user ID.

There are some problems with the shortcut approach we took in the first article:we modified generated code, and if for any reason we had to regenerate that code our changes would be lost. This exposure is bigger in this release because the Content and User Resource wizard has been enhanced to allow you to make changes to a resource and regenerate the code without having to recreate a resource from scratch. The best practice is to write a translator class and register it through the WebSphere Personalization Resource Console. We have included the source for this class in the ZIP file. As you can see when you look over UserInfo.java, the translateAuthID method simply strips out the extra characters that are included in the user ID, and then returns the name in the format required by the WebSphere Personalization run time.

Follow these steps to register and activate this class:

  1. Copy the UserInfo.class, including the entire directory package structure to C:\WebSphere\AppServer\wcp\runtime\lib. This location is part of the application server's extended classloader, where the bulk of the WebSphere Personalization and WPCP classes are loaded from. Once the class is in this classloader, all resources are able to access it. For this class to be picked up initially, or to be updated, you must restart the application server.
  2. Bring up the Personalization Resource Console by opening a browser window and entering: http://<YourFullyQualifiedHostName>/wps/PersAdmin/adminFrame.jsp
  3. You will receive a security challenge. Log in with: user ID: wpsbind
    password: wpsbind
  4. In the console, select the Security tab.
  5. Select Customer in the Collections list box, then select Add Translator.
  6. Enter com.ibm.poc.pzn.UserInfo for Specify the full translator class name, then click the Add/Change button (Figure 47).
    Figure 47. Adding a translator class
    Adding a translator class
  7. Click the Enable Security button to enable and activate security.
  8. In order for the WebSphere Personalization run time to pick up this new class, you must stop and start the application server in the WebSphere administrator's console.

14. Test the portlet

  1. You are now ready to test your personalized portlet. Before you test it, make sure that you register three user ID/password combinations: User ID: user1 Password: user1
    User ID: user2 Password: user2
    User ID: user3 Password: user3
  2. Log in to the portal with the user ID: user1.
  3. Select the page group and page where you added the portlet. The page shown in Figure 48 opens, displaying details of the PersSamplePortlet.
    Figure 48. Portlet output for user1
    Portlet output for user1
  4. Next, login as user2. Notice that user2 has a balance of 1002, and therefore has beenclassified as preferred. Because of this, user2 sees news which is relevant to preferred customers (Figure 49).
    Figure 49. Portlet output for user2
    Portlet output for user2

Conclusion

In this article, we have demonstrated how to develop a simple personalized portlet. In general, these are the same steps you will use to create more complicated personalized portlets. Specifically, we showed you how to use the Portal Toolkit, and how to extract the short form of the user ID from LDAP; these topics are unique to using WebSphere Personalization with WebSphere Portal. We also introduced several best practices, such as creating a data source for the resource classes to use, and using the WebSphere Personalization Resource Console to register a user translation class. We will explore more advanced topics in future articles.

Top of page



Download

NameSizeDownload method
PersPortalFiles.zip0.1 MBFTP|HTTP

Information about download methods


Resources

About the authors

Bruce R. Olson is a member of the WebSphere Enablement team in Raleigh. Bruce has worked as a consultant on WebSphere products since 1999, specializing in Personalization, content publishing, and WebSphere Portal. Before joining the WebSphere team, he helped to design and implement the IBM C++ User Interface Class Library and coauthored two editions of Power GUI Programming. Before that, Bruce worked in the IBM Artificial Intelligence Support Center, working with Expert Systems.

Venkata V. (Vishy) Gadepalli is a member of the WebSphere Enablement team in Raleigh. He has over five years experience in the IT field. His current area of expertise is enabling and consulting for WebSphere products, specializing in WebSphere Application Server, Portal, and Personalization. Before joining the Enablement team, Vishy was a member of the WebSphere development team.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=13181
ArticleTitle=IBM WebSphere Developer Technical Journal: Integrating WebSphere Portal and WebSphere Personalization -- Part 2
publish-date=06022003
author1-email=bolson@us.ibm.com
author1-email-cc=
author2-email=vgadepal@us.ibm.com
author2-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers