If your model will run as a portlet as well as a widget or standalone application, you may need to implement conditional code based on whether the model runs in the context of the IBM® WebSphere® Portal, as a standalone application, or as an IBM WebSphere Portlet Factory widget application.
You can do this by profiling the builder inputs or builder enablement that needs to be excluded or different when not running in a different context, and using the Portal Execution Mode profile selection handler to select a profile based on whether your model is running as a portlet or in another mode.
When running in portal mode, you 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 you 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 Application Server portlet, you would perform these steps.
- Add a method builder call to the model, specifying the name, arguments, and other information.
- 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.
Parent topic: Developing widgets with IBM WebSphere Portlet Factory