Share data between different IBM WebSphere Portal applications
Easy steps for using a Shared Data application object in Personalization rules
IBM® WebSphere® Portal includes a personalization (PZN) business rules engine that is used to select and make visible certain content based on user attributes or other criteria. WebSphere Portal includes several application objects that are ready for immediate use. These objects make available information such as user history, session, or request information to this rules engine. This tutorial shows you how to use the Personalization API to configure a Shared Data Application object and use that object to share data between different Portal applications.
The Shared Data application object is one of the preinstalled application objects that are available to use with the Personalization rules in IBM WebSphere Portal. You can use this object to share data between different browser requests, for example, when complex data needs to be shared between WebSphere Portal web applications. The properties for the Shared Data object are stored in a dedicated object, which in turn is stored on the user's session object. Therefore, the object is session-scoped and available to the user throughout that user's session. Read more on Data Sharing application objects in the IBM Knowledge Center
One advantage of using this object is that it allows code to share complex data objects between different requests. Request object attributes can also be used to pass information to Personalization rules. However, it is not uncommon for code to have different request objects. The values set in one request object are not visible to other request objects. Similarly, portlets in an application might not have access to the HTTP requests of other portlets.
The example scenario
This tutorial walks through a simple example of how to use a Shared Data application object with a Personalization visibility rule. The object is initialized on the home page, where the object's properties are also set. Then, the Personalization visibility rule is created. In this example, the rule governs whether to show or hide the page or portlet based on the value of a property on the object. This rule can be added to other pages, such as the child page of the custom landing page or to any portlets on that child page. In this example, the child page or portlet is always shown for all authenticated users, as the object property is set to a constant. However, the property value can be determined by more complex dynamic conditions. For example, the property can be set to different values depending on which Portal group the user belongs to.
Set properties for a Shared Data application object
To set properties for a Shared Data application object in a JSP page (for example in the file Theme Default.jsp), use the Personalization API as shown in the Java scriptlet code in Listing 1.
Listing 1. Setting properties for a Shared Data application object
... <%@page import="com.ibm.websphere.personalization.context.PersonalizationContext"%> <%@page import="com.ibm.websphere.personalization.RequestContext"%> <%@page import="com.ibm.websphere.personalization.applicationObjects.SharedDataApplicationObject"%> <%SharedDataApplicationObject sharedOne = new SharedDataApplicationObject();RequestContext requestContext = PersonalizationContext.getRequestContext(request, null);sharedOne.init(requestContext);sharedOne.put("isPreferred","true");%> ...
This code initializes the SharedDataApplicationObject and sets the
isPreferred property to true.
Add a property to the Shared Data application object
In the PZN Business Rules editor, add the
property to the Shared Data object, in the same manner as for request or
session objects as shown in Figure 1. You can then add it to a rule.
Figure 1. Selecting a dynamic property for a PZN rule
Add the object property to a PZN rule
Add the Shared Data
isPreferred property to a PZN visibility
rule and add this rule to a WebSphere Portal page or portlet. This
visibility rule shows or hides portlets or pages to an authenticated user,
depending on the value of
isPreferred property. The page or
portlet is visible if the value of
isPreferred is true and
hidden otherwise. Because the
isPreferred value is set to true for this example (Figure 2), the visibility rule
always shows associated pages or portlets for the authenticated users.
Figure 2. Using the Shared Data application object property in a PZN visibility rule
This tutorial showed you how to use the Personalization API of IBM WebSphere Portal to initialize a Shared Data application object and use it in a visibility rule. By using Shared Data application objects, Portal applications can share complex data objects between HTTP requests in other Portal applications.