Sun Java System Portal Server 7.1 Developer's Guide

Chapter 11 Overview of the Portlets

This chapter contains the following sections:

What is a Portlet?

Portlet refers to pluggable web components that process requests and generate content within the context of a portal. Conceptually, portlets are equivalent to the providers. The portlets process requests coming from the portal and generate content for inclusion on the desktop. The portlets generate dynamic content and interact with web clients through a request and response paradigm.

The portlets only generate markup fragments and not complete documents. The portal aggregates portlet markup fragments into a complete portal page. Portlets are not directly bound to a URL; they have URL rewriting functions to create hyper links within their content. Portlets have predefined portlet modes (VIEW, which is mandatory, EDIT, and HELP, which are optional) described in their deployment descriptor and window states that indicate the function that the portlet performs and the amount of real estate in the portal desktop. They can store transient data in the portlet session in two different scopes: the application-wide scope and the portlet private scope.

In the Sun Java System Portal Server software, portlets are managed by a Portlet Container. The Portlet Container manages portlets in the same way that the web container manages servlets. The portlet container manages the life cycle of the portlets within the Portal Server. The life cycle refers to the creation, operation, and destruction of the portlets. The portlet container is also responsible for routing the incoming requests to the correct portlet. The portlet container also provides a persistent storage mechanism for the storage of portlet preferences. The portlet states for Portal Server are hardcoded in the portlet container and is not extensible.

Overview of Developing and Deploying Portlets

The portlet API includes a GenericPortlet abstract class that implements the Portlet interface and the PortletConfig interface. This class provides access to the following common portlet functionality:

Dispatch processing for portlet URLs

The render method is implemented to determine current portlet mode and to call the appropriate method.

Accessor for the portlet’s configuration

The class includes an easy mechanism to obtain portlet’s initialization parameters.

Accessor for the portlet’s context

The class includes an accessor method to obtain a reference to the PortletContext interface that enables portlets to interface with the container.

ProcedureTo develop and deploy portlets

  1. Develop the portlet class files.

    A portlet must implement the javax.portlet.Portlet interface. This interface defines the basic behavior that the portlet container expects from a portlet.

  2. Create the portlet specific XML fragments and package it into a WAR file.

  3. Deploy the Portlet web application.

  4. Create and view the Portlets.