Concepts of cooperative portlets


The following sections describe the basic concepts of cooperative portlets:

 

Overview

Cooperative portlets subscribe to a model for declaring, publishing, and sharing information with each other using the WebSphere Portal property broker. Portlets subscribe to the broker by publishing typed data items, or properties, that they can share, either as a provider or as a recipient.

The target portlets optionally provide actions to process the properties that it receives. Action processing in target portlets does not need to distinguish between an action initiated within its own portlet area and an action initiated by the transfer of a portlet property value. Each action is associated with a single input parameter and zero or more output parameters, which provide information to the action about the objects in which the property value should be bound, such as the request or the session). Each parameter is associated with exactly one property. Parameters associated with input properties are called input parameters, while those associated with output properties are called output parameters. Instead of actions, target portlet can receive property changes directly through the PropertyListener interface.

At runtime, the property broker matches the data type of output properties from a source portlet with the data type of input properties from one or more target portlets. If a match is determined, the portlets are capable of sharing the property. The actual transfer of the property can be initiated by one of the following methods:

Cooperative portlets can be source portlets, target portlets, or both.

 

Features of cooperative portlets

The property broker is used to facilitate development of portlets that may be dynamically integrated, without requiring a-priori coordination at development time. Portlets may be developed and deployed separately or together, but as compatible portlets are placed on the page, they can exchange information and react in a coordinated manner, thus improving the end-user experience. Conversely, as portlets are removed from the page, the remaining portlets on the page will still be able to function correctly and in a coordinated manner.

Some of the specific features of cooperative portlets include:

 

Property broker programming model

The property broker runtime comprises of a generic wrapper portlet, which is used to wrap each portlet enabled for cooperation, as well as a broker component. These components also interface with the WebSphere Portal core runtime. The purpose of the wrapper is to intercept calls to the application portlet and interface with the broker appropriately, to transparently register actions supported by the portlet, and to initiate data transfer from source to target portlets using the property broker. The wrapper is packaged in each cooperative portlet's WAR file. The broker centrally maintains a repository of actions on each portlet, together with the parameter type information, performs source and target matches at runtime using this information, and generates additional markup to allow users to trigger data transfers across portlets.

Cooperative portlets can use declarative, programmatic, or a combination of these approaches to register properties to the property broker.

 

Declarative approach to publishing properties

Source portlets use a set of custom JSP tags to specify the type and value of the data being contributed. At the point where such a tag occurs, the property broker inserts markup that can display the pop-up menu of action choices for the user. The markup provides a standard icon that allows the user to initiate the transfer of the output property. If a wire has been created, however, the icon is no longer presented. Instead, the output property is automatically propagated according to the settings saved in the wire.

Advanced options on the JSP tags allow the programmer to indicate whether a broadcast action is to be added to the menu, or to scatter of a set of property values (rather than a single value) to all portlets. The appearance of the icon and menu can be determined by the theme. WebSphere Portal provides the default icons in...

was_root/installedApps/hostname/wps.ear/wps.war/themes/html/

Target portlets associate their actions with an input property which has been declared as an XML type. The actions are declared using WSDL, with a custom binding extension which specifies the mapping from the abstract action declaration to the actual action implementation. Associated with each action is a single input parameter described by an XML type and zero or more output parameters, each described by an XML type. Each input or output parameter encapsulates exactly one property. The input property's type is used for matching the action to sources, and its value is filled in when the end-user triggers the action using Click-to-Action. The output parameters, if specified, are used to automatically trigger other compatible actions (ones which can consume the same type) on other wired portlets every time the action executes (this may be used to trigger chains of related actions).

The declarative approach is simpler. Few changes need to be made to existing portlets to enable them to interact with other cooperative portlets on the page. Existing portlets that already use action processing simply declare their actions to the property broker using WSDL.

 

Programmatic approach to publishing properties

The property broker provides APIs to give developers more control over how portlets handle input and output properties. The programmatic approach might be a better option over the declarative approach when the portlet needs to:

Use the programmatic approach, target portlets can use the setProperties() method to receive change notifications in place of actionsPerformed().

The following packages are provided for portlets to publish properties to the property broker programmatically:

 

Combination approach to publishing properties

A portlet could use the declarative approach for many of these features, such as registering actions and properties, and selectively make calls for exploiting the programmatic features, such as enabling and disabling selected actions within a session.

 

Property transfer using wires

Wires are used to save property transfers between portlets on a page. If a wire is present when the user clicks on the Click-to-Action icon, no selection menu is shown. Instead the wired action is automatically fired. Wires may also be used to initiate property value transfers in the absence of Click-to-Action icons, simply as a side effect of an action being executed on the source portlet. Wires can be created using the Portlet Wiring Tool or within the portlet by holding Ctrl while clicking on the Click-to-Action icon. If a source portlet uses Click-to-Action menus to support wires, the name attribute of the <c2a:encodeProperty/> tag must refer to an output property that has been registered with the property broker. Output properties may be registered declaratively, using WSDL, or programmatically, using Java APIs. See Enabling source portlets using the declarative approach for more information.

If a wired action is associated with output properties, the property broker checks for output property values once the action has finished executing. If such properties are found, the property broker examines wires with source ends that correspond to the output properties of the action. If such wires are found:

 

Sample flow of cooperative portlet interaction

An example request-response flow involving cooperative portlets is illustrated in the following figure. This example uses Click-to-Action as an illustration, but it is similar to the series of events in the programmatic or wired interaction scenarios.

Click-to-Action flow


Click to action flow


This comprises the following steps:

  1. During portlet initialization, the wrapper processes any action WSDL file associated with the application portlet and registers the actions and properties with the broker.

  2. During the render phase of a request cycle, JSPs associated with source portlets are processed. The custom Click-to-Action tags result in calls to the property broker, which determines matching actions on the page based on type information, and generates additional code to display the icon used to invoke the pop-up menu.

  3. After all render phase portlet callbacks have been completed, the portal assembles the response page and returns it to the client.

  4. The end-user may click on the icon for a source to view a menu of compatible actions on the page and select one.

  5. A new request is generated, containing the chosen source and action information and sent to the portal.

  6. The portal core runtime delivers the action to the target portlet. This is intercepted by the wrapper, which may interact with the broker to further process the request before delivering the action to the target.

 

Event handling

The portlet programming model involves an event phase and a render phase in each request-response cycle (see Portlet events). The event phase is when the property broker delivers notifications to cooperative portlets and when the cooperative portlets can notify the property broker of property value changes. During the event phase, an action may be delivered on one portlet. If the property broker is used, this may result in other actions being triggered on other portlets. The event phase is followed by the render phase, in which each portlet is asked to return markup, which is then aggregated in a single page. The markup may embed actions which can be invoked by the user. The page is then returned to the client (such as a browser).

At any point during the event phase, a portlet may explicitly publish the value of an output property to the property broker by invoking the changedProperties() method. This is an alternative to the declaration of output parameters for actions and binding the output parameter values to the request or session when the action is invoked. This may happen in the callback method associated with the start of the event phase (beginEventPhase()), in the invocation of the setProperties() method, or in the portlet action method invocation. Such publish calls are dealt with by the property broker in the same manner as output parameters of actions: wires associated with output properties are examined and the property values propagated using the information in the target end of the wire.

Note that the process may continue recursively; the property broker detects loops and breaks them.

The property broker guarantees the completion of all property value notifications to target portlets by the end of the event phase, whether through portlet actions, or through the special setProperties() method. The end of the event phase is indicated by the invocation of the endEventPhase() method.

During the render phase of each request cycle, source portlets can write visual controls representing source data to their output stream. The end-user interacts with the visual control in the response to trigger one or more actions on other portlets on the page.

During the event phase of the subsequent request, the action is invoked on the corresponding target portlet or portlets.

 

Action Activation and Deactivation

Actions which are registered are active by default as soon as the portlet is initialized and is active. Actions may be explicitly specified to be inactive when the portlet is initialized. Such actions may be selectively activated in individual sessions by invoking the activateActions() method on the PropertyBrokerService interface. The corresponding deactivateActions() call may be made to deactivate actions activated earlier for the session. Only target actions which are active for the current session are invoked to receive property values published by source portlets or passed via user triggers. Actions which are active may be deactivated in the current session by issuing the corresponding deactivateActions() method call on the PropertyBrokerService interface. Deactivated actions are not invoked by the property broker and do not appear in Click-to-Action menus.

Actions may be deactivated if the portlet needs to get into a certain state before activating the actions. In some cases, it may be appropriate to make the default behavior for certain actions to be inactive, so that they may be programmatically activated by the portlet when it reaches a certain state. This may be achieved by using the value "false" on the isActiveOnStartup attribute on the action element in the WSDL description, or by setting the corresponding property on the Action object if programmatic registration is used.

See also