Portlet Concepts

The Portlet Phase Model

When a request arrives at a portal targeted to a portlet, the portlet container executes portlet code according to a phase model.

There are three processing stages containing five processing phases, defined as follows:

The portlet API allows creation of URLs that can be included into portlet markup in order to activate the portlet processing stages.

  • The Action URL, or Partial Action URL triggers preparation stage processing.
  • The Render URL triggers aggregation stage processing.
  • The Resource URL triggers resourec stage processing.

When a stage is triggered, the processing phases within that stage are executed.

Action Phase
The portlet can perform updates and set up render state for the Aggregation Stage. The action phase is initiated thru form post targeting the portlet. During action phase processing, the portlet can fire events, resulting in event phase processing.
Event Phase
During event phase processing, the portlet container routes any fired events to the portlets subscribed to the events. Portlets define the events they can fire and receive through configuration.
Header Phase (new with V3):
Called for all portlets before the overall portal response is committed. Portlets can contribute header values, cookies, and markup for the HEAD section and can declare page resource dependencies.
Render Phase:
Called after the header phase for all portlets has been executed. The portlet generates its markup for aggregation into the portal page. During the render phase, the portlet may only generate markup that the portal is able to integrate into the portal page.
Resource Stage
Initiated by an Ajax request from portlet JavaScript code using a resource URL. During the resource phase, the portlet has nearly complete control over the response returned to the client. It may produce markup, JSON data, or binary data, for example.

The portlet container drives portlet phase execution by setting up the execution environment for each portlet and phase and calling the corresponding portlet lifecycle methods.

The portlet participates in the phase model by implementing the corresponding lifecycle methods and by using the portlet API to carry out the appropriate tasks.

The Portlet Lifecyce Methods

Each portlet phase has a corresponding lifecycle method. The portlet container executes the prrocessing phase by calling the portlet lifecycle method. Each phase is provided with specific request and response objects. Methods can implemented using the interfaces Portlet, ResourceServingPortlet, EventPortlet and HeaderPortlet. Portlets can be configured through annotation or using the portlet deployment descriptor.

Portlets can implement the lifecycle methods by extending the GenericPortlet class or by using the extended method annotations.

When the extended method annotations are used, portlet lifecycle methods can be arbitrary methods in java classes. The methods are identified by the portlet lifecycle method annotations and have relaxed method signature requirements as compared to interface methods. When the method annotations are used, portlets are implicitly configured if no data beyond that provided in the annotation is required. Additional configuration is possible through annotation or portlet deployment descriptor.

  • Set up / tear down: @InitMethod, @DestroyMethod
  • Preparation stage: @ActionMethod, @EventMethod,
  • Aggregation stage: @HeaderMethod, @RenderMethod,
  • Resource stage: @ServeResourceMethod