How to modify Personalization 3.5 Toys Sample to run on WPS installation

 

Introduction

Personalization 3.5 is installed as part of WPS1.2 installation process. This version of Personalization is the same one as the standalone product. In the standalone product, there is a Toys Sample that demonstrates the usage of Personalization rules. However, the sample code assumes that the Personalization Application Server is installed in the “Default Server” application server, whereas in the WPS installation, it is installed in the “WebSphere Portal Server” application server. If you follow the original sample’s installation instruction, the sample will not work properly. This tip explains the extra steps needed to install the sample into the WPS installation.

 

Steps

 

1.      Download the SG246214 Redbook and Toys sample from IBM redbooks website:

http://w3.itso.ibm.com/itsoapps/Redbooks.nsf/9445fa5b416f6e32852569ae006bb65f/bd15a321abc10e0185256967006e7a3f?OpenDocument&Highlight=0,SG246214

2.      Follow the redbook instructions to create the database

3.      Follow the redbook instructions to import the Toys samples into WebSphere Studio 3.5. Note: You do not need to follow the instructions for the Recommendation Engine.

4.      Before publishing the sample code to the application server, you need to change the following publishing properties:

a.       Click on Window->Publishing. On the right panel, right click on “localhost”, select properties

b.      Set the Webapp web path to the same value as in your wps web application. The default value, if you did not change it during WPS installation, is /wps. (You can get this value by opening the WAS Admin Console, then navigate to HOSTNODE->WebSphere Portal Server->WPS Servlet Engine->wps. The value is in the Web Application Web Path field under the General tab.)

c.       Click on the “Targets…” button. Change the html publishing target to:

<wps_dir>/app/web

d.      Change the servlet publishing target to <wps_dir>/app/servlets

5.      Publish the sample code to the application server.

6.      Before trying out the sample, add a invoker servlet to your wps web application.

a.       On the WAS Admin Console, select Console->Tasks->Add a Servlet

b.      Select “No” not to use exisiting servlet jar files or directory. Click next.

c.       Navigate to Nodes->WebSphere Portal Server->WPS Servlet Engine. Select wps. Click next.

d.      Select Enable Serving Servlets by Classname

e.       Click finish

7.      Open your web browser and go to:

http://yourhostname/wps/StudioSamples/Personalization/index.html

to access the Toys Personalization Sample.

 

Notes on using Personalization in portlets

 

  1. Before using the bean, call its setRequest() method with the HttpServletRequest object

eg

<% HttpServletRequest sRequest = ((PortletRequestImpl) request).getServletRequest(); %>

<jsp:useBean class="com.ibm.wps.portlets.samppers.UserType" id="userType"><% userType.setRequest(sRequest); %></jsp:useBean>

 

  1. Classifer rules can be evaluated with the isClassifiedAs() method.

eg

if (userType.isClassifiedAs("music")) { %>

    <TD><IMG src="<%=response.encodeURI("images/samppers/music.gif")%>" width="96" height="30" border="0"></TD><%

      }

 

  1. Use the response.encodeURI() method to generate the URL for other resources. See point 2 for example.

 

  1. Binding and action rules can be evaluated by calling the getRuleContents() method.

 

eg

<TR><TD><%=theSiteNews.getRuleContent(0).getTITLE()%></TD></TR>

 

eg

<% com.ibm.wps.puma.Coynews[] rules = theClearanceNews.getRuleContent();

for(int i=0;i<rules.length;i++){ %>

   <TR><TD><%=rules[i].getTITLE()%></TD></TR>

<% } %>

 

  1. The User resource that comes defined with the Personalization Sample portlet is created from the com.ibm.wps.puma.User class. This means that you can use the methods of this class to access the User resource when returned by a rule.

eg

Locality:<%=theCurrentUser.getRuleContent(0).getLocalityName()%>

The com.ibm.wps.puma.User source code is available with the WPS installation.

 

 

Hosted by www.Geocities.ws

1