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.
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:
- Create a JDBC Driver and data source
- Create a portlet project in Application Developer
- Create the user and content resources
- Create a content spot for the rules
- Add the content spots to the JSP file
- Add code to the JSP to populate the content spots
- Export the portlet WAR file from Application Developer
- Deploy the portlet in WebSphere Portal
- Create the WPCP project
- Create the personalization rules
- Associate the rules with the content spots
- Publish the WPCP project
- Translate the LDAP user ID
- 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,
CustomerandCustomernews. All of the user data is defined by and stored in theCustomertable. The content model store is theCustomernewstable. - 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:
- Start the Websphere Application Server Administrator's Console.
- Select Console => New => JDBC Provider....
- 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
- Since we are using local DB2, select the first line, as shown in Figure
2, then select OK.
Figure 2. Selecting the Implementation Class
- Select the Nodes tab on the "JDBC Provider Properties" dialog, then select Install New....
- Select your node in the "Install Driver" window (Figure 3), then
select Specify Driver....
Figure 3. Install Driver window
- 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.
- 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\javadirectory. - Highlight the file and click the Set button, as shown in Figure 4.
Figure 4. Setting the Driver file
- Now, back on the "Install Driver" window (Figure 3), select the Install button to install the driver on your node.
- Finally, select OK to finish creating the JDBC driver (Figure 5).
Figure 5. Completing the JDBC Provider Properties window
- Right-click on Data Sources and select New....
Figure 6. Creating the Data Source
- Enter the following values for the fields in the "Data Source Properties"
dialog, as shown in Figure 7.
Field Value Name PersSampleDatasourceJNDI name jdbc/jdbcdb2SAMPLE(the name we used when creating our resources)databaseName SAMPLEuser wsdemopassword wsdemo1
Figure 7. Data Source Properties window
- 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.
- To launch Application Developer:
- Select Start => Programs => IBM WebSphere Studio Application Developer => IBM WebSphere Studio Application Developer.
- Select Perspective => Open => Other to launch the "Select Perspective" window.
- In this window, select Portlet and then OK.
- From the Application Developer tool bar, select File => New => Portlet application project to launch the "Create a Portlet project" wizard.
- Ensure that Use default location is selected, then enter the following values, as shown in Figure 8. When
finished, select Next.
Field Value Project name PersSamplePortletEnterprise Application project name PersSamplePortletEARContext root /wps/PersSamplePortlet
Figure 8. Create a Portlet project dialog
- On the next screen, select the Basic Portlet radio button, and select Next. The "Create a Portlet project - Basic portlet parameters" dialog opens.
- Enter the following values for these fields, as shown in Figure 9. Accept
the defaults for the remaining fields. When finished, select Next.
Field Value Concrete portlet title PersSamplePortletPortlet class name MyPersSamplePortletContext root /wps/PersSamplePortlet
Figure 9 Basic portlet parameters dialog
- In the Navigator view, examine the project that you just created.
You should see two folders named
PersSamplePortletEarandPersSamplePortlet, with a directory structure that resembles Figure 10.
Figure 10. 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:
- Select Perspective => Customize.
- Expand the Other folder.
- Select the WebSphere Portal content publishing toolbar check box, then OK.
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:
- Select the WPCP Content and User Resource wizard icon, as shown in Figure 11.
Figure 11. Launching the Content and User Resource wizard
- On the first screen of the wizard, select the Web users radio button, leave all other defaults, then select Next.
- In the "Database Connection" dialog, enter the following values
for these fields, as shown in Figure 12. When finished, select Connect to Database.
Field Value Connection name PersSampleConnectionUser ID wsdemoPassword wsdemo1Database vendor type select DB2 UDB V7.2
Figure 12. Database Connection
- When the connection completes successfully, a new set of tabs displays (Figure 13).
- 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
- Select Next to go to the Columns tab.
- 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.
- 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
- Click Next to go to the "Resource Generation Options" dialog, then select Finish.
- 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
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

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:
- Leave the Web Content radio button selected, which is the default.
- Make sure that you select the Customernews table as your content resource (Figure 13).
- 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
Figure 18. 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.
- In Application Developer, select the Content Spot wizard icon, shown in Figure 19.
Figure 19. Launching the Content Spot wizard
- In the Content Spot wizard, enter the following values, as shown in Figure
20. When completed, select Finish.
Field Value Package PersSampleDisplay Name getCurrentUserSpotClass Name getCurrentUserSpotReturn Type select PersSample.Customer
Figure 20. Completing the Content Spot wizard
- 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.
- In Application Developer, navigate to the
View.jspfile and double-click the file to open it in the JSP Editor. - Select the Design tab, and erase all of the existing content.
- In the Navigator pane, select getCurrentUser.class,
hold the left mouse button down, drag the file to the top of the
View.jspedit window, and drop the file here.An "Attributes" window opens. Click OK to accept the default values. - Complete the same steps to drag and drop
getCustomernews.classon the JSP. - 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.
- 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:
Change the above lines to look like this:<jsp:useBean class="PersSamplePortlet.getCurrentUserSpot" id="getCurrentUserSpot"/>
<jsp:useBean class="PersSamplePortlet.getCustomernewsSpot" id="getCustomernewsSpot"/><jsp:useBean class="PersSamplePortlet.getCurrentUserSpot" id="getCurrentUserSpot">
The above changes are required for every content spot that you add to a page to link to the WebSphere Personalization run time.
<% getCurrentUserSpot.setRequest(request); %>
</jsp:useBean>
<jsp:useBean class="PersSamplePortlet.getCustomernewsSpot"
id="getCustomernewsSpot">
<% getCustomernewsSpot.setRequest(request); %>
</jsp:useBean>
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
- Select the Design tab in the JSP Editor.
- Select Insert => Table to create a new table. Specify 2 rows and 1 column, and then click OK to close the dialog.
- Next, double-click on the table to launch its "Attributes" dialog.
- Select the Dynamic tab.
- Select the Loop check box, then enter the value of
1for both the Start row and End row, as shown in Figure 21.
Figure 21. Bean Attributes and Bean Property Selection dialogs
- Select the Browse button to launch the "Bean Property Selection" dialog (also in Figure 21). Select getCurrentUserSpot.ruleContent[], then click OK.
- 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: ". - Position the cursor to the right of the text, and select Insert => Dynamic Elements => Property Display.
- In the "Attributes" dialog, select Browse to launch the "Bean Property Selection" dialog.
- This time, select the USERID attribute, and click OK on each of the dialogs to close them.
- Select the second row of the table, and enter
"Your account balance is: ". - Repeat these steps steps h through k, but this time select the Balance attribute.
6.2 Create a table to display personalized news
- Complete
View.jspby 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 of2for both Start row and End row, and entergetCustomernewsSpot.ruleContent[]for Loop property field, as shown in Figure 22.
Figure 22. Bean Property Selection dialog for the second table
- When you have finished with the "Bean Property" dialog, highlight
the first row of the table, and enter
"Here is your personalized news...". - 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.
- 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
- Save
view.jspby 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.
- In Application Developer, right-click on the PersSamplePortlet project, and select Export WAR... (Figure 24).
Figure 24. Exporting the WAR file
- Choose the location you want to export the
WAR file to, and click Finish (Figure 25).
Figure 25. Exporting the WAR file details
8. Deploy the portlet in WebSphere Portal
- To deploy the portlet on WebSphere Portal, open a browser window and enter
:
http://<YourFullyQualifiedHostName>/wps/myportal - Log in with:
user ID:
wpsadmin
password:wpsadmin - To install your portlet, select the Install Portlet tab in the Portal Administration group and follow the prompts.
- Next, you will add the portlet to the page of your choice.Select the Edit Layout tab in the Work with Pages group.
- 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
- In the next window, enter the value
Persin the Name contains field, then select Go. - 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
- The portlet is now added to the page.Select Activate to activate the page (Figure 28).
Figure 28. Activating the page
- Use the Security tab in the PortalAdministration group to grant view access of your portlet to all authenticated users.
Now, create a project in WPCP where you can define your rules using the personalization rule editor.
- To launch the WPCP, enter the following in a browser window:
http://<YourFullyQualifiedHostName>/wps/wcp/index.jspRemember to substitute the fully qualified host name for the localhost. - Log in to the workspace with the following values (or whatever password
you created for the
wcpadminuser).: user ID:wcpadmin
password:password - From the Administration tab, select Projects/Editions, and then Add Project (Figure 29).
Figure 29. Adding a WPCP project
- 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):
Field Value Name PersSamplePortletContext Root wps/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 Path C:\WebSphere\Appserver\installedApps\ PersSamplePortlet_WPS_PA_801.ear\PersSamplePortlet.war
It is very important that you look in yourinstalledAppsdirectory 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 Root C:\Program Files\WSAD\workspace\PersSamplePortletDefault Process Simplest Change Process
We aren't doing anything with workflows but the dialog requires you to make a selection for this field.Version Provider None
We will not be using any version control.Quick Edit YesLock Yes
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
- Click Save to exit the dialog.
10. Create the personalization rules
We will create three types of rules:
- Profiler rule
We will create theUserLevelProfiler rule, which classifies the user based on the balance in theiraccount. - Action rules
We will create six action rules, the first beingGetCurrentUser, 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 theGetCustomerNewsbinding 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
- 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
- Edit the rule by entering the following values, as shown in Figure 32:
Field Value Rule Name UserLevelRule Type Profiler
Figure 32. Editing the UserLevel Profiler
- 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. - 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
- Select is equal to, and change it to is less than or equal to.
- Select value, and enter
100. - 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.
- Click Save when you
are done.
Figure 34. Final UserLevel Profiler rule
10.2 Create the GetCurrentUser Action rule
- Click on the + button to create your first action rule.
- Edit the rule by entering the following values:
Field Value Rule Name GetCurrentUserRule Type Select Content
This is the most commonly used type of Action rule. - Select Resource.Attribute. On the next screen, select Customer and Userid, then select Save.
- 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.
- Click on Save to save the finished rule.
10.3 Create the GetBasicNews Action rule
- Press + to create your next action rule.
- Name the rule
GetBasicNews, repeat the steps in the previous section so that it resembles Figure 36.
Figure 36. Final GetBasicNews
10.4 Create the four remaining Action rules
Following the same steps, create the remaining four rules:
GetAdvantageNewsGetAllNewsGetPreferredNewsGetPremiumNews.
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:
- Ensure that Bindings is selected in the drop-down menu for the rule types, then select + tostart the rule editor.
- Name the rule
GetCustomerNews. - When you click on Profiler, a list of available Profilers appears. Select the UserLevel Profiler (the only one we have defined).
- 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.
- 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
- Complete the
GetCustomerNewsBinding rule, as shown in Figure 38.
Figure 38. GetCustomerNews Binding rule
- 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
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:
- 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.
- 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
Figure 41. View after assigning rules to content spots
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.
- Select the Administration tab.
- Select Publish Servers, then click on the Add Server icon in the upper right pane (Figure 42).
Figure 42. Adding a publish server
- Fill in the attributes for the Publish server as follows, and as shown
in Figure 43, then select Save.
Field Value Server Name PersPortletServerServlet URL http://<YourFullyQualifiedHostName>/wps/Persadmin/publishtarget?ContextRoot= /wps/WPS_PA_801War Root Path C:\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 yourinstalledAppsdirectory to get the correct context root. We are using the publish servlet provided byPersadmin, 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 ID wpsbindRealm Password wpsbind
Figure 43. Adding a new publish server
- Select the Content tab.
- Select the Files folder, then click on the Publish icon (Figure 44).
Figure 44. Publishing the project
- 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
- 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
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=comTo 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:
- Copy the
UserInfo.class, including the entire directory package structure toC:\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. - Bring up the Personalization Resource Console by opening a browser window and entering:
http://<YourFullyQualifiedHostName>/wps/PersAdmin/adminFrame.jsp - You will receive a security challenge. Log in with:
user ID:
wpsbind
password:wpsbind - In the console, select the Security tab.
- Select Customer in the Collections list box, then select Add Translator.
- Enter
com.ibm.poc.pzn.UserInfofor Specify the full translator class name, then click the Add/Change button (Figure 47).
Figure 47. Adding a translator class
- Click the Enable Security button to enable and activate security.
- 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.
- 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:
user1Password:user1
User ID:user2Password:user2
User ID:user3Password:user3 - Log in to the portal with the user ID:
user1. - 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
- Next, login as
user2. Notice thatuser2has a balance of1002, and therefore has beenclassified aspreferred. Because of this,user2sees news which is relevant to preferred customers (Figure 49).
Figure 49. Portlet output for user2
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.
| Name | Size | Download method |
|---|---|---|
| PersPortalFiles.zip | 0.1 MB | FTP |
Information about download methods
- WebSphere Portal content publishing (product documentation)
- WebSphere Portal for Multiplatforms Version 4.2.x InfoCenter
- Portlet Catalog
- InfoCenter updates
- Integrating WebSphere Portal and WebSphere Personalization -- Part 1: Building a Personalized Portlet
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)





