In this topic ...Creating Conditional Code Based on Execution Mode Profiling Based on Execution-Mode with WPS Execution Mode Handler |
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.)
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.
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.
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.
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:
Click here for complete information about profiling Factory models.
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: