Personalizing Portlets

 <  Day Day Up  >  

The goal of personalization is to map user properties to content. Personalization can de divided into two categories: implicit and explicit. In explicit personalization , users define the content they want to see, as in a portlet offering different news options from which users can choose. If a user chose to see only entertainment news, the portlet would display only entertainment news when it displays content to that user. In implicit personalization , users are unaware that personalization is taking place, as in an application that's programmed to display content based on whether users meet some defined requirements. For example, in an application that's keeping track of a rewards program, you might want different content displayed for Gold and Platinum members . To accomplish these goals, WebLogic Portal provides a personalization engine consisting of user profiles, rules, and content management.

User Profiles

User profiles are used to track the attributes of each user. Each attribute, known as a property , is created in WebLogic Workshop.

Creating User Profiles

User profiles are part of the data project that's created with a portal application. To create a new user profile, navigate to the data , userprofiles folder in the WebLogic interface. Right-click the userprofiles folder, and then choose New, User Profile Property Set. To add a property to the user profile, drag one of the four options from the Palette to the property set. When deciding which type of property to use, you need to determine whether the property is single valued or multivalued and whether it's restricted or unrestricted.

Single valued means the property can contain only one value, such as the user's age. Multivalued means the property has more than one value ”for instance, the user's preferred lottery numbers . When a property is multivalued, it's stored as an ArrayList .

A restricted property defines the possible values that can be stored. For example, if a property consists of the flavors in Neapolitan ice cream, the only choices are vanilla , chocolate, or strawberry. An unrestricted property can contain any value, such as a property that simply stores a user's favorite ice cream flavor.

After making these decisions, drag the appropriate tag ”Single Unrestricted, Single Restricted, Multiple Unrestricted, or Multiple Restricted ”from the Palette onto the property set. Table 13.2 lists the possible attributes of a property.

Table 13.2. User Profile Attributes

ATTRIBUTE

DESCRIPTION

Property Name

The name of the property in the user profile.

Description

An optional attribute to describe the property's use.

Data Type

The type that's stored in the property; you can choose from Text, Numeric, Float, Boolean, and Date/Time.

Selection Type

This is single or multiple. Notice that you can change the type that you originally drag from the Palette.

Value Range

Restricted or unrestricted. You can also change the value range you originally drag from the Palette.

Values

If the property is restricted, you supply its possible values and the default. If the property is unrestricted, this attribute is used to set the default value.

In the Wonderland Casino example, you want to change the meaning of a high roller . Currently, the determination is based on how many chips a user buys during a purchase. The Wonderland Casino has decided to track how many total chips guests have bought during the time they have been guests. To do this, a guestProperties user profile is created with a chipsBought property, as shown in Figure 13.2.

Figure 13.2. A user profile in WebLogic Workshop.

graphics/13fig02.gif

Accessing User Profiles

Now that you have created user profiles in Workshop, you need to access them in your Page Flows and JSPs. You can access them via a control, if you're in an action method of a Page Flow, or you can access them via a JSP tag if you're in a JSP. A common method is to get values with JSP tags and set values using controls.

To get values using a JSP tag, drag the getProperty tag from the Portal User Management palette. The getProperty tag has three attributes: id , propertyName , and propertySet . The propertySet attribute is the user profile that the property belongs to; in the Casino example, it's guestProperties . The propertyName is the property in the user profile to retrieve; for the Casino example, it's the chipsBought property. The id attribute is an optional property; if you give it a value, a variable is created with the name you supplied. If no id attribute is present, the tag simply displays the value returned from the tag. If you created a multivalued property previously, you should supply the id attribute because the tag won't display the returned ArrayList correctly. The following code is an example of using the getProperty tag from the User Management tag library:

 <um:getProperty propertyName="chipsBought" propertySet="guestProperties"/> 

The best way to set a property is in an action method of a Page Flow. First, you add a User Profile control in the Action View of a Page Flow. Many methods deal with manipulating user information, but the method to use for this purpose is the setProperty() method. Before using the setProperty() method, you must get the user's profile object. A ProfileWrapper is a lightweight version of a user profile and is returned by the getProfileForUser() method. After getting the ProfileWrapper , the setProperty() method is used to store the property. This process is shown in Listing 13.3.

Listing 13.3. Setting a Property Value in an Action
 protected Forward purchaseChips(BuyChipsBean form) {    amt = form.getChipAmt();    String confirmNum = form.getConfirmationNumber();    try{        ProfileWrapper pwrap =               userProf.getProfileForUser(getRequest().getRemoteUser());        Long rawValue =              (Long)userProf.getProperty(pwrap,"guestProperties","chipsBought");        int value = amt + rawValue.intValue();        userProf.setProperty                 (pwrap,"guestProperties","chipsBought",new Integer(value));    }catch (Exception e) {System.out.println(e);}    return new Forward("confirmed"); } 

This code updates the BuyChips application so that the total number of chips for a user is aggregated every time he or she buys chips.

Using Rules to Personalize Content

Now that your users have properties you can manipulate, you can use rules to divide them. Rules are logical groupings of users based on user properties, HTTPRequest objects, HTTPSession objects, and the date. The goal is to match content with users who qualify for it. There are two types of rules: user segments and content selectors.

User Segments

User segments are the basis for personalizing applications using WebLogic Portal. Although it's true you do not need user segments in other forms of personalization, the user segments you create are reuseable. Using user segments to factor out common user attributes and then adding to them later is a good practice.

To create a segment, expand the data folder in Workshop, expand the segments folder, right-click the globalClassifications folder, and choose New, User Segment. Figure 13.3 shows the different conditions that user segments can have. The different conditions are as follows :

  • The visitor has specific characteristics.

  • The visitor's HTTP session has specific properties.

  • The visitor's HTTP request has specific properties.

  • It is after a given date.

  • It is after a given date and time.

  • It is between two times.

  • It is between two dates.

  • It is between two date/times.

Figure 13.3. Available conditions for a user segment.

graphics/13fig03.gif

There are really two different types of conditions ”property based or time based ”and the other conditions are variants of them. Property-based conditions deal with a user, an HTTP session, or HTTP request properties. Time-based conditions occur before, between, or after dates and/or times.

The available conditions are to search for properties from the HTTP request, the HTTP session, the user characteristics, and a range of date and time options. Note that nothing is actually placed into the HTTP request or the HTTP session. The rules engine simply checks to see whether the selected properties exist in their respective areas.

The Wonderland Casino wants to create a user segment to determine whether a user is a high roller. When the check box The Visitor Has Specific Characteristics is selected, it means you're going to compare against a user profile. You can then select profiles and properties for evaluating this segment. In this example, you'll compare the chipsBought property to 10,000, which is the value supplied by the Wonderland Casino.

Save the segment, and it's then ready to be executed. To access segments, you use the JSP tag <pz:div> . The important attribute is rule , which defines the rule to be executed. When using the <pz:div> tag, note that any content placed between the start and end tag is displayed only if the user is part of the segment. The pz:div> tag is part of the pz.tld tag library. Listing 13.4 shows the usage of the <pz:div> tag.

Listing 13.4. Using the <pz:div> Tag
 <pz:div rule="highRoller">         <p>         Since you have bought <um:getProperty propertyName="chipsBought" propertySet="guestProperties"/> chips,         You have qualified for high roller status.             <br>             When you check in to the casino you will receive information on             how to access the high roller only rooms.             <br>         </p>         </pz:div> 

In this code, if the user is a highRoller , the content between the start and end tags is displayed. The content is entirely up to the developer who writes the code. The next section describes a more dynamic way to get content.

Content Selectors

Content selectors are similar to user segments. In fact, they have a segment piece, where you can use a predefined segment or create a new user segment. The difference between segments and content selectors is where the content is chosen . As you saw in the previous section, the displayed content was based on what the developer put between the start and end <pz:div> tags. With a content selector rule, the rule determines the content that's displayed. Every content selector rule includes a content query that's executed against a content management system (CMS). The results can then be interpreted in the JSP to display the returned content.

The initial window for a content selector is similar to the window shown in Figure 13.3. However, a content selector has an extra condition for using an already defined user segment and includes the link for the content search. Figure 13.4 shows the Content Search dialog box, where you select the content property set and the property to compare. When you click the Add button, you are given the option to select whether you want to compare the property against a static value or against a value a user possesses. Comparing against a user's value can make the displayed content quite dynamic.

Figure 13.4. Adding a content search.

graphics/13fig04.gif

Next, you execute the rule from a JSP using the <pz:contentSelector> tag. Two important attributes must be supplied: rule and id . As with user segments, the rule attribute is just the name of the rule to fire. The id attribute is a variable name that stores the array of results returned from the CMS. An example of this is shown in Listing 13.5.

Listing 13.5. Firing Content Selector Rules
 <pz:contentSelector rule="highRollerImage" id="images"/> <ut:forEachInArray array="<%=images%>" id="anImage" type="com.bea.content.Node">  <img src="<%= request.getContextPath() + "/ShowBinary" + anImage.getPath() %>">  <br> </ut:forEachInArray> 

The <ut:forEachInArray> tag is a utility tag in WebLogic Portal that loops through an array of objects. To display the image retrieved from the CMS, the ShowBinary servlet is used.

 <  Day Day Up  >  


BEA WebLogic Workshop 8.1 Kick Start
BEA WebLogic Workshop 8.1 Kick Start: Simplifying Java Web Applications and J2EE
ISBN: 0672326221
EAN: 2147483647
Year: 2004
Pages: 138

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net