ShowTable of Contents
Within WCM, content can be categorized. Normally, this is used to allow WCM menus to display content related to specific categories. However, it is also possible for users within WCM to have categories associated with their profile. This can be done within theWCM Authoring UI
, the user can select their own categories using a Taxonomy Element
, or can be done programmatically
. Once the user is associated with categories, a WCM menu can then retrieve content that is associated with the same categories as the user.
In this example, we will show how these categories can be used within PZN rules to retrieve the content that is related to the categories that the user is interested in.
Creating and Deploying the Custom Application Object
There are 2 approaches that we can use for this application object. One is to retrieve the values that WCM has associated with the user. This is useful if the end user has categories stored within WCM, the dynamic mapper approach is being used (categories added to WCM Users programmatically), or the end user is selecting their own categories using the taxonomy tree. The other approach is that the custom application object can associate categories for the specific user programmatically. This approach is useful, because categories can selected based on things like user cookies, request attributes in the current request, etc. This particular example will retrieve the categories directly from WCM for the user.
Creating the WCM JSP Component
In order to retrieve the categories for the current user, the application object have to have the current users categories set on it. Normally, this work would be delegated to the application object itself. However, because of the way that WCM retrieves user categories that are not persisted to the user lookaside table, this has to be done during a rendering request. To get around this, we have a WCM JSP component that will retrieve the current user categories, invoke the custom application object, and set the categories for the current user on it.
- Create a .jsp file, named PopulateUserCategories.jsp. In this example, I will be storing the JSP directly within the WCM JSR rendering portlet, so store it in /PROFILEHOME/installedApps/cellname/PA_WCMLRingPortJSR286.ear/ilwwcm-localrende.war/jsp/html. For the text of the .jsp, enter the following:
<%@ page session="false" isELIgnored="false"%>
<%-- java imports --%>
<%@ page import="java.util.*"%>
<%@ page import="javax.portlet.*"%>
<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="com.ibm.websphere.personalization.custom.appobject.*"%>
// get the application object, set it's categories to the current user
// get the WCM workspace:
Workspace usersWorkspace = (Workspace)request.getAttribute(Workspace.WCM_WORKSPACE_KEY);
if (usersWorkspace == null)
// get the users cats
UserProfile theProfile = usersWorkspace.getUserProfile();
if (theProfile == null)
String categories = theProfile.getCategories();
if (categories != null)
String holdingString = "";
for (int x = 0; x < categories.length; x++)
holdingString += categories[x];
if (x < categories.length - 1)
holdingString += ",";
UserCategoriesObject userCatObject = new UserCategoriesObject();
if (userCatObject == null)
System.out.println("userCatObject not null setting "+holdingString);
What this code does is:
- retrieve the categories for the current user
- Retrieves the custom Application Object
- Next, create a WCM JSP Component. Place the JSP component in whichever library you wish. Name it JSP - PopulateUserCategories.jsp. In the Path, enter /jsp/html/PopulateUserCategories.jsp
- Save and close.
Create the Custom Application Object
Install the Custom Application Object Code
Create the Application Object within PZN UI
Creating the PZN rules
To display the results, we will create a WCM PZN Component in order to reference the rule.
- Navigate to the WCM Authoring UI, open the library that you wish to store the PZN component in.
- Create new -> Component -> Personalization
- Name the component PZN - Current User Category Content
- For the Personalization Element, click New. Create the rule to select Web Content whose category is associated with CurrentUserCatsApp.currentCategoriesUuidString:
- Click Save.
- In the PZN Component, for the Design for each Menu search result, put the following:
[Property type="content" context="autofill" field="title"] - [Property type="content" context="autofill" field="categories"]<br>
This will render the title of the content, as well as the categories that the content is associated with. This will tell us whether the rule is working.
- Save and close the component
Creating the WCM HTML Component
Now, we need to first invoke the custom JSP to populate the custom application object's properties for user categories, and then use that same value within the PZN rule. In order to do this, we just create an HTML component, and reference both the JSP and PZN component within.
- Create an HTML Component, name it HTML - PZNRuleWrapper
- Populate it with the following:
[Component name="Web Content/JSP - PopulateUserCategories.jsp"]
[Component name="Web Content/PZN - Current User Category Content"]
- Save and close the component.
Rendering the Results
Now that we have the WCM Components in place, we just have to reference them from an HTML component