ShowTable of Contents
Within the IBM® Web Content ManagerTM
(WCM) rendering portlet, it is possible to configure the portlet to be associated with WCM Categories, Site Areas, and Authoring Templates. Although these values are intended to be used for WCM menu components, it is possible that you would want to use a PZN rule to retrieve WCM content based on this information. This article discusses how to accomplish this task.
WCM rendering portlet configuration options
In the WCM JSR286 rendering portlet, it is possible to associate the portlet with specific WCM Categories, Site Areas, and Authoring Templates (see figure 1).
Figure 1. Portlet configuration
The intent for these settings is to allow WCM menu components to retrieve content based on these portlet configuration values. It's also possible to leverage these properties, using a PZN rule within a WCM Personalization component. In this example, we use the value of the Categories setting to retrieve content based on the category that is configured within the portlet.
Creating the JavaServerTM Page (JSP)
In this example, we store the JSP directly within the WCM JSR rendering portlet, because the portlet tags must be used within the custom JSP. For the text of the JSP, enter code shown in listing 1.
Listing 1. Code for text of JSP
<%@ page session="false" isELIgnored="false"%>
<%-- used tag libraries --%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="/WEB-INF/tld/wcm.tld" prefix="wcm"%>
<%@ taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.0.1/resolver" prefix="resolver"%>
<%@ taglib uri="/WEB-INF/tld/ibm-portlet-ext-v61.tld" prefix="portletExtV61" %>
<%-- java imports --%>
<%@ page import="java.util.*"%>
<%@ page import="javax.portlet.*"%>
<%-- define javax.portlet.* objects --%>
PortletRequest thePR = (PortletRequest)request.getAttribute("javax.portlet.request");
PortletPreferences preferences = thePR.getPreferences();
Enumeration prefNames = preferences.getNames();
String categoryString = preferences.getValue("CATEGORY_OVERRIDE","");
// since the categories are stored as comma delimited string, grab the individual values
String categoryValues = categoryString.split(",");
// for PZN, have to add uuid: to the beginning of the uuid for the category
String finalCategoryString = "";
if(x < categoryValues.length-1)
finalCategoryString += finalCategoryString+",";
// now, place the value within the request
Save this file as RetrievePortletParameters.jsp, upload it into the JSR286 portlet, and place it in /WPHOME/wp_profile/installedApps/wps61/PA_WCMLRingPortJSR286.ear/ilwwcm-localrende.war/jsp/html.
At a high level, the code is pulling a specific portlet preference (in this case, CATEGORY_OVERRIDE, which is used to store the WCM Category), and then turning the uuid value into a value that a PZN rule can leverage to retrieve the relevant WCM content.
Note the last line:
This adds the value of the category string from the portlet configuration to the request. This will make it available to the PZN rule.
Creating the WCM JSP Component
To leverage the JSP from within the WCM PZN component, we need to create the WCM JSP Component. To do this:
- Navigate to the WCM Authoring Portlet and then to the library in which you want the JSP Component stored.
- Select New --- Component --- JSP Component.
- Name the JSP Component "JSP - PZN Portlet Configuration."
- In the path, enter: /jsp/html/RetrievePortletParameters.jsp
- Save and Close.
Creating the WCM PZN Component
Now we create the WCM PZN component to retrieve the WCM content:
Figure 2. Manage Properties
- Navigate to the WCM Authoring Portlet and then to the library in which you want the component stored.
- Select New --- Component --- Personalization.
- Name the component WCMPZNPortletConfigurationRule, and allow the location to be the library you are in or select another location.
- In the Personalization Element section, click the New button.
- Create a rule that retrieves Web content whose category "is associated with" (is associated with being the value of the PZN rule condition for the category section), and select Request --- Manage Properties (see figure 2):
6. On the next window, click the Add Dynamic Property button and, in the Add Dynamic Property form, enter WCMPZNRuleCategories for the name of the property, as well as for the name to use in the rule editors (see figure 3). The type of the attribute should be Text; click Save.
Figure 3. Add Dynamic Property window
7. Once it's saved, select the new property on the form, and click Done. Now click again on the "is associated with" (is associated with being the value of the PZN rule condition for the category section), and select Request -> WCMPZNRuleCategories (see figure 4).
Figure 4. WCMPZNRuleCategories
8. Save the rule; your PZN Component is now populated with a value. In the Design for each menu result section, enter:
[Property type="content" context="autofill" field="title"] - [Property type="content" context="autofill" field="categories"]<br>
This causes the content Title being followed with the categories with which the content is associated, proving that the rule is working.
9. Save and close the component.
Creating the WCM HTML Component
Now, in order for the PZN rule to have access to the request attribute that the JSP is populating, we have to reference both the JSP and the PZN component. 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 - pzn portlet configuration"]
3. Save and close the component.
Rendering the results
Now that we have the PZN component, we just need to configure a WCM JSR286 rendering portlet to point to the HTML component, as well as configure it to specific categories. Here we use the configuration shown in figure 5. Note the piece of content that is tagged with the Movies category.
Figure 5. Results rendered
After clicking Apply, you can see our content being returned by the PZN Component (see figure 6).
Figure 6. Content returned
In this article, we covered the following:
- Using PZN rules to retrieve content from WCM.
- How to retrieve dynamic request attributes to be used by PZN rules.
- How to programmatically retrieve portlet configuration parameters.
Tell us what you think
Please visit this link to take a one-question survey about this article:
About the author
Christopher Knight is a WCM/PZN Level 3 Support Software Engineer. He has been working with WCM/PZN for many years.