Profiling a Portlet

In this topic ...

Creating Conditional Code Based on Execution Mode

Profiling Based on Execution-Mode with WPS Execution Mode Handler

Profiling Based on the WebSphere Group

Profiling Based on a User's Locale

We can profile a portlet like any other Factory model. You can use profiles to allow for Configure (optional in JSR 168 portals ) or Edit mode functionality. We can use profiles to vary your portlet's behavior based on the Group to which the user belongs and/or whether or not the model is being executed as a portlet or as a standalone web application.

This page describes how to profile a portlet according to WebSphere Group information and the execution mode of the model. In WebSphere portlets, we can also use profiles to implement Configure and Edit functionality. (Procedures for JSR 168 portlets will be similar. Refer to your portal's documentation for additional information.)

 

Creating Conditional Code Based on Execution Mode

If your model will run as a WebSphere portlet as well as a Factory application, you may need to implement conditional code based on whether the model runs in the context of the IBM WebSphere Portal or as a Factory application. We can do this by using the WPSPortalMode profile set and the Portal and Standalone profiles to determine the code to execute.

When running in Portal mode, we can cast the HttpServletRequest object returned by the webAppAccess.getHttpServletRequest() method to a PortalRequest object. The same is true for the PortalResponse and PortalSession objects. The request contains the PortletConfig object as an attribute and we can access it with code similar to the following:

PortalConfig pc = webAppAccess.getHttpServletRequest().getAttribute("bowstreet.websphere.portlet.config");

For example, if you wanted to get the locale out of the request, regardless of whether the model runs as a WebSphere portlet, you would perform these steps.

  1. Add a Method builder call to the model, specifying the name, arguments, and so forth.

  2. Profile the Method Body input of the Method builder call, specifying the WPSPortalMode profile set and the mode-specific method body.

    The value for the GetHeaders_Body entry in the Standalone profile would be something like:

    String locale = webAppAccess.getHttpServletRequest().getLocale();

When the model runs, the appropriate method body gets used.

 

Profiling Based on Execution-Mode with the WPS Execution Mode Handler

Another way to select a profile based on run mode is using the WPS Execution Mode Handler. This handler is for creating models that vary depending on whether they are running standalone or in a WebSphere Portal. This handler returns "Portal" if the model is currently running as a portlet in WPS; or "Standalone" if running standalone.

To use this, you create a profile set that has two profiles called "Portal" and "Standalone." Choose "WPS Execution Mode Handler" as the selection handler. In your models, we can profile builder inputs to this profile set. For example, we can make it so that portal-only functionality (such as calling Portal API's) is disabled when running the model is running standalone. This can be very useful for developing/testing, so that we can run your models standalone and also have extra functionality when running in a WebSphere Portal environment.

 

Profiling Based on the Group

We can alter the way your portlet works according to the Group to which the user belongs by profiling the underlying Factory model and associating the profile set with the WPS Group Segment Handler.

To profile a portlet based on the WebSphere Group to which a user belongs:

  1. In WebSphere Portal Admin: Create any users and groups for your portal application.

  2. In Designer: Create your models, profile sets, and profiles.

  3. In Designer: Profile the builder call inputs that will drive the variability of your portlet.

  4. In Designer's Profile Manager: Use the Select Handler editor to set the selection handler for the profile set to WPS Group Segment Handler.

  5. In Designer's Profile Manager: In the Manage Profiles editor, edit the profile and use the Add External button to specified a group name. You must specify the WebSphere Group name exactly.

  6. In WebSphere Portal Admin: Set permissions for each of your portlets for each WebSphere Group.

  7. In WebSphere Portal Admin: Test your profiling by logging in as one of the users and accessing the profiled portlets.

Click here for complete information about profiling Factory models.

 

Profiling Based on a User's Locale

We can use the current Language Locale in the Portal to drive the localization of a portlet. The WPS User object allows you to get the language preference of users from their user profile.

The Locale Selection Handler is used to select a profile by matching a user's locale to a profile within a specified profile set. This handler determines the user's locale by using the HttpServletRequest.getLocale() method on the Locale object to get the locale name as a string.

The locale value is built up with the language, country, and variant separated by underscores ( "en_US_WIN" or "de_DE"). The language is always lower case (such as "en" for English) and the country is always upper case (such as "GB"). If the language is missing, the string will begin with an underscore (for example, "_GB").

The Locale Selection Handler can also be used with a standalone web application.

To profile a portlet based on the user's locale:

  1. In WebSphere Portal Admin: Create the users for your portal application.

  2. In Designer's Profile Manager: Create a Locale profile set (with language-specific profiles) and use the Select Handler editor to set the selection handler for the profile set to Locale Selection Handler.

  3. In Designer: Profile the builder call inputs that will drive the variability of your portlet.

  4. In Designer's Profile Manager: In the Manage Profiles editor, edit the profiles and for each profile use the Add External button to associate one or more locale names for the profile segment. For example, if you created a profile named "English", you should associate en and en_US with that profile.

  5. In WebSphere Portal Admin: Set permissions for each of your portlets for each WebSphere language locale.

  6. In WebSphere Portal Admin: Test your profiling by logging in as one of the users and accessing the profiled portlets.