WebSphere

 

Portal Express, Version 6.0
Operating systems: i5/OS, Linux, Windows

 

Comparing the standard portlet API to the IBM portlet API

 

+

Search Tips   |   Advanced Search

 

  1. Introduction
  2. Relationship to servlet API
  3. Comparing common portlet API concepts
  4. Comparing elements of the API
  5. Concepts unique to the Java Portlet Specification
  6. Concepts unique to the IBM portlet API
  7. User attributes for standard portlets
  8. Limitations

 

Introduction

Between the Java Portlet Specification and the IBM portlet API, the fundamental concepts of portal servers are the same. The portlet container is the runtime environment for portlets using the portlet API. The portal server...

  1. Receives the client request for a page
  2. Calls the portlets for the page
  3. Calls the container to provide the output for each portlet.
  4. Aggregates the output from all portlets on the page

 

Relationship to servlet API

The IBM portlet API extends the servlet API and many of the main interfaces...

The standard portlet API does not extend the servlet API, but takes advantage of much of the functionality provided by the servlet specification, such as...

Standard portlets can call servlets and package them in the same portlet application.

Portlets, servlets and JSPs within the same portlet application share the same classloader, application context and session.

 

Comparing common portlet API concepts

For both portlet APIs, there is one portlet object instance per portlet configuration in the Web deployment descriptor. The APIs differ in how each portlet object is represented in the portal.

Logical representation of portlets in the IBM portlet API

The PortletSettings object ( 1 ) provides the portlet with its unique set of configuration parameters and values. Configuration parameters are initially defined in the portlet deployment descriptor, but can also be added or modified by the portal administrator. There can be many PortletSettings objects, parameterizing the same portlet object according to the Flyweight pattern, provided on a per-request basis. Each PortletSettings object along with the portlet object comprises a concrete portlet.

Logical representation of portlets in the IBM portlet API

When users edit the settings in a portlet according to their preferences, the settings are saved to persistence using the PortletData object ( 2 ). There can be many PortletData objects parameterizing the same concrete portlet. Each PortletData object along with the concrete portlet comprises a concrete portlet instance.

When multiple users interact in different browser sessions with the same concrete portlet instance on a portal page, each user sees a particular user portlet instance ( 3 ), which is a concrete portlet instance parameterized with...

  • session
  • mode
  • window state

Logical representation of portlets in the Java Portlet Specification

In WebSphere Portal Express, standard portlets, like IBM portlets, can also be configured on two levels, by an administrator and by individual users. However, the standard portlet API has no concept of a concrete portlet application or concrete portlets. The number of configuration layers is opaque to the programming model; the portlet configuration is contained within a single PortletPreferences object which aggregates these configuration layers.

Preferences can be marked in the portlet.xml as read-only so that they may be customized only by administrators ( 1 ) using configure mode or through the administration portlets. Preferences that are not marked read-only can be modified by users in edit mode ( 2 ).

The parameterized view of a portlet for an individual user interaction is called portlet window in the Java Portlet Specification. The standard portlet API uses render parameters as an alternative way to hold interaction state for a portlet window. A portal page can contain more than one portlet window for a single portlet, each portlet window associated with unique portlet mode, state, and render parameters ( 3 ).

Logical representation of portlets in the JSR 168 portlet API

 

Comparing elements of the API

Utility classes

The Portlet interface is the main abstraction for both the Java Portlet Specification and the IBM Portlet API. Portlets for both APIs should extend the corresponding utility classes, which provide default functionality for the portlet.

  • Standard portlets should extend the GenericPortlet class.
  • IBM portlets should extend the PortletAdapter class.

Life cycle

The following table compares the portlet life cycle between IBM portlets and standard portlets.

IBM Portlet API Java Portlet Specification Description
init() init() Called after the portlet has been loaded and instantiated. Portlets use this method to perform one-time operations, especially those that might incur performance costs. The portlet can access its configuration, including initialization parameters, within this method.
initConcrete() none The Java Portlet Specification does not have a concept of a concrete portlet.
service() render() Used to render output to the client. These methods are typically applied using the mode-specific implementations of...

  • doView()
  • doEdit()
  • doHelp()

Using the standard portlet API, this method is invoked when the portal receives a render request.

none processAction() Used by the portlet to...

  • Receive parameters
  • Update state
  • Perform any other necessary action processing

This is not part of the life cycle of the IBM portlet because the IBM portlet must implement an ActionListener for its counterpart, actionPerformed(), to be called. This method is invoked when the portal receives an action request.

destroyConcrete() none The Java Portlet Specification does not have a concept of a concrete portlet.
destroy() destroy() Called when the portlet is to be removed from service().

Request handling

Similar to servlets, portlets interact with clients using a request/response paradigm implemented by the portlet container. In a typical scenario, a user selects a page and the portlet container sends the request to each portlet on that page to render output in its response. These requests are called render requests. Other requests, however, are launched when the user interacts with one of the portlets on the page, such as clicking a submit button. Such actions generate URLs to the portlet, which might require the portlet to process an action before sending the response. These are called action requests.

In the servlet model, all request handling would be performed in the service() method. Portlets, however, use a two phase processing that is split between an event phase and a render phase. If the portlet receives an action request, then the event phase is started in which the portlet's action processing method is called. The result of this action could invoke actions for other portlets on the page. After actions have been complete for all portlets on the page, each portlet's rendering method is called. The event phase is guaranteed to complete before the start of the render phase.

The following table describes the differences between the IBM Portlet API and the Java Portlet Specification for handling requests.

IBM Portlet API Java Portlet Specification
The portlet must implement an ActionListener to participate in the event phase. The actionPerformed() method is invoked to handle action requests.

Request and session attributes can be set in the action and retrieved from the subsequent render phase.

During the render phase, the service() method is called. Methods for both phases take the same PortletRequest and PortletResponse objects as arguments. There is no distinction in the API between action request and response objects and render request and response objects.

The processAction() method is invoked to handle action requests. The main difference is that the action request and response objects are different from render request and response objects. The portlet can set render parameters or session attributes during the action that are available in the render call, but request attributes are not transferred between action and render phase.

For both APIs, if the portlet extends the appropriate utility class, the service() method dispatches the doView(), doEdit() or doHelp() methods, depending on the current portlet mode.

Portlet mode

Modes allow portlets to provide different interfaces depending on the task that is required of them. The following modes are supported by both APIs.

View

View mode is used for displaying portlet content. Utility class invokes doView() method.

Edit

Edit mode is used for personalizing the portlet (portlet data). Utility class invokes doEdit() method.

Help

Help mode is used for displaying help on the portlet Utility class invokes doHelp() method.

The following table describes support for other modes in each API.

IBM Portlet API Java Portlet Specification
Configure mode is used by an administrator for globally configuring the portlet (portlet settings). Changes affect all occurrences of the portlet on all pages. Utility class invokes doConfigure() method. Config mode supported as a custom mode. In config mode, the administrator can globally update the configuration of a portlet, including portlet's read-only preferences. Changes affect all occurrences of the portlet on all pages. In config mode, the portlet's read-only preferences can be updated by the administrator.
No custom modes. Allows portlets and portal server implementations to support custom modes. At runtime, portlets use PortalContext.getSupportedPortletModes() to retrieve the modes supported by the portal and adapt accordingly. The Java Portlet Specification also suggests these custom portlet modes: about, config, edit_defaults, preview, and print. Vendors can also define other portlet modes.

The current portlet container in WebSphere Portal Express supports config and edit_defaults.

Portlet window states

Window states indicate the amount of space that the portlet consumes on a page. The portlet can query its state to determine the visible size of the content it should render. The following states are supported by both APIs.

Normal

The portlet is provided equivalent space as other portlets on the page or in the same container.

Maximized

No other portlets are displayed, providing maximum space for the portlet's use.

Minimized

Only the portlet's title bar is displayed. The Java Portlet Specification allows the portlet to provided a limited amount of output, but for WebSphere Portal Express, the portlet's output is not displayed at all.

The following table describes support for other states in each API.

IBM Portlet API Java Portlet Specification
Solo Supported only as a custom window state. WebSphere Portal Express does not support solo state for standard portlets.
No custom states. Allows portlets and portal implementations to define custom window states. At deployment time, the portal can map custom portlet window states from the portlet descriptor to its own custom window states, or it can ignore them. At runtime, portlets use PortalContext.getSupportedWindowStates() to retrieve the modes supported by the portal and adapt accordingly.

WebSphere Portal Express does not support custom window states for standard portlets.

Portlet URLs

Portlet URLs allow the portlet to create a URL to itself. When the user clicks a link or performs an action that launches the URL, it creates a new request to the portal targeted to the portlet. The following table describes how each API implements this functionality.

IBM Portlet API Java Portlet Specification
PortletResponse.createURI() creates a URI to the portlet. An action can be set on the PortletURI object, so that the actionPerformed() method of the portlet is called before the service() method. RenderResponse.createRenderURL() creates an URL that triggers the render() method of the portlet.

RenderResponse.createActionURL() creates an URL that triggers the processAction() method of the portlet before the render() method.

HTML form processing must be done using an action URL. Render and action parameters are separate for standard portlets; parameters set on an action URL are not available to the render() method unless they are passed explicitly using ActionResponse.setRenderParameter().

See Request handling for details about the action and render method.

Namespace encoding

Portlets must contribute identifiers and names in their portlet output that is unique within the portal page. For example, two portlets could appear on a page, both with an anchor named return. Namespace encoding allows the portlet to ensure these names do not clash by adding the portlet's namespace to the anchor name. The following table shows how namespace encoding is performed in the Java source for each API.

IBM Portlet API Java Portlet Specification
PortletResponse.encodeNamespace(name) RenderResponse.getNamespace(name) returns a namespace that is valid for the current user session.

See JSPs for a comparison of how namespace encoding is performed for JSPs.

JSPs

The following table compares how JSPs are invoked from the portlet class for each API.

IBM Portlet API Java Portlet Specification
PortletContext.include() PortletRequestDispatcher.include()

The request dispatcher serves as a wrapper for a resource at the path indicated by getRequestDispatcher(path).

The following table describes the differences in the tag libraries for each API.

IBM Portlet API Java Portlet Specification
<portletAPI:init/>

PortletRequest
PortletResponse
PortletConfig

<portlet:defineObjects/>

RenderRequest
RenderResponse
PortletConfig

<portletAPI:createURI/>

Creates a URI that points to the portlet. To invoke an action in an IBM portlet, include the <portletAPI:URIAction/> tag and action parameters.

<portlet:renderURL/> creates an URL that will trigger the render() method of the portlet.

<portlet:actionURL/> creates an URL that will trigger the processAction() method of the portlet before the render() method.

<portletAPI:encodeNamespace/> <portlet:namespace/> returns a namespace that is valid for the current user session.
Other tags provided by the IBM portlet API tag library Use JSTL tags

URLs to portlet resources

In WebSphere Portal Express, resources within a portlet cannot be invoked using relative URLs. For URLs to these resources to work, they must be encoded using the encodeURL() method of the portlet response. Resources include any file in the portlet application that is referenced or invoked from the portlet or one of its JSPs, including:

  • images
  • applets
  • multimedia
  • JSPs
  • servlets

The following table explains the differences between each API for using the encodeURL() method.

IBM Portlet API Java Portlet Specification
Use the encodeURL() method of the response and specify the path to the resource. See the example in Figure 1. Use the encodeURL() method, just as you would with the IBM portlet, except that you also have to add the context path of the portlet from the request. See the example in Figure 1.

Figure 1. Example of using encodeURL() methodJava Portlet Specification

<%= portletResponse.encodeURL("/images/photo01.jpg") %> 

 

IBM Portlet API

<%= 
portletResponse.encodeURL(renderRequest.getContextPath()
 +  "/images/photo01.jpg") 
%> 

Caching

Both APIs provide the means for portlets to cache their output and improve performance and response times. The table below describes the differences in the implementations.

IBM Portlet API Java Portlet Specification
Expiration timer set in the portlet.xml. The IBM Portlet API supports invalidation-based caching. Can be dynamically changed by the portlet when its getLastModified() method is called. Expiration timer set in the portlet.xml. Can be dynamically changed by the portlet using the EXPIRATION_CACHE property of the RenderResponse.

Portlet configuration

For both APIs, the PortletConfig object is made available to portlet during initialization.

IBM Portlet API Java Portlet Specification
Provides the initialization parameters defined in the web.xml. Initialization parameters can be read using the getInitParameter() method of the Portlet interface. Provides the initialization parameters, which can be defined in the portlet.xml or the web.xml. Initialization parameters can be read using the getInitParameter() method of the PortletConfig interface.

 

Concepts unique to the Java Portlet Specification

 

Concepts unique to the IBM portlet API

 

User attributes for standard portlets

The following table lists the attributes from the appendix of the Java Portlet Specification, PLT.D User Information Attribute Names, and the corresponding attribute name in Member Manager (wmmAttributeName). The portlet container also supports arbitrary user attributes. To specify arbitrary user attributes, the portlet needs to specify the Member Manager attribute name in the portlet.xml deployment descriptor under the <user-attribute/> element and can obtain the attribute value by inspecting the USER_INFO map in the request.

User attribute name Member Manager equivalent
user.gender ibm-gender
user.employer o
user.department ou
user.jobtitle ibm-jobTitle
user.name.prefix ibm-personalTitle
user.name.given givenName
user.name.family sn
user.name.middle ibm-middleName
user.home-info.telecom.telephone.number homePhone
user.home-info.online.email ibm-otherEmail
user.business-info.postal.street street
user.business-info.postal.stateprov stateOrProvinceName
user.business-info.postal.postalcode postalCode
user.business-info.postal.country countryName
user.business-info.telecom.telephone.number telephoneNumber
user.business-info.telecom.fax.number facsimileTelephoneNumber
user.business-info.telecom.mobile.number mobile
user.business-info.telecom.pager.number pager
user.business-info.telecom.online.email ibm-primaryEmail

 

Limitations

The standard portlet container for WebSphere Portal Express has the following limitations:

RenderResponse.setTitle(java.lang.String title)

This method is not supported by WebSphere Portal Express.

Portlet URL security

The setsecure() method of the PortletURL interface is not supported.

The portlet URL will always be the same security level of the current request.

Likewise, the secure attribute of the <portlet:actionURL/> and <portlet:renderURL/> tags is not supported. See PLT.7.1.2 Portlet URL security in the specification for more information.

Programmatic security

Programmatic J2EE authorization using the isUserInRole() method of the portlet request is not fully supported, since any <security-role-ref/> elements in the portlet deployment descriptor are ignored. Role assignments for J2EE roles declared by means of <security-role> elements in the web.xml deployment descriptor can still be verified via the isUserInRole() method.

The getUserPrincipal() method of the portlet request always returns null if application server security is not enabled. The getRemoteUser() method of the portlet request always returns a unique value for each user, even with security disabled, so that it can be used for personalization purposes, such as storing user-specific preferences. Therefore, you can always use the code fragment request.getRemoteUser() != null to check if a user has logged in.

The return value with disabled security might not be a human-readable string and will be different from the value returned when security is enabled.

See PLT.20.3 Programmatic Security in the specification for more information.

Specifying security constraints

The <security-constraint/> element in the portlet deployment descriptor is not supported. See PLT.20.3 Specifying Security Constraints in the specification for more information.

 

Related information