javax.portlet

Class GenericPortlet

public abstract class GenericPortlet extends Object implements Portlet, PortletConfig

The GenericPortlet class provides a default implementation for the Portlet interface.

It provides an abstract class to be subclassed to create portlets. A subclass of GenericPortlet should override at least one method, usually one of the following:

Normally there is no need to override the render or the doDispatch methods. Render handles render requests setting the title of the portlet in the response and invoking doDispatch. doDispatch dispatches the request to one of the doView, doEdit or doHelp method depending on the portlet mode indicated in the request.

Portlets typically run on multithreaded servers, so please note that a portlet must handle concurrent requests and be careful to synchronize access to shared resources. Shared resources include in-memory data such as instance or class variables and external objects such as files, database connections, and network connections.

Field Summary
PortletConfigconfig
Constructor Summary
GenericPortlet()
Does nothing.
Method Summary
voiddestroy()
Called by the portlet container to indicate to a portlet that the portlet is being taken out of service.
protected voiddoDispatch(RenderRequest request, RenderResponse response)
The default implementation of this method routes the render request to a set of helper methods depending on the current portlet mode the portlet is currently in.
protected voiddoEdit(RenderRequest request, RenderResponse response)
Helper method to serve up the edit mode.
protected voiddoHelp(RenderRequest request, RenderResponse response)
Helper method to serve up the help mode.
protected voiddoView(RenderRequest request, RenderResponse response)
Helper method to serve up the mandatory view mode.
StringgetInitParameter(String name)
Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.
EnumerationgetInitParameterNames()
Returns the names of the portlet initialization parameters as an Enumeration of String objects, or an empty Enumeration if the portlet has no initialization parameters.
PortletConfiggetPortletConfig()
Returns the PortletConfig object of this portlet.
PortletContextgetPortletContext()
Returns the PortletContext of the portlet application the portlet is in.
StringgetPortletName()
Returns the name of this portlet.
ResourceBundlegetResourceBundle(Locale locale)
Gets the resource bundle for the given locale based on the resource bundle defined in the deployment descriptor with resource-bundle tag or the inlined resources defined in the deployment descriptor.
protected StringgetTitle(RenderRequest request)
Used by the render method to get the title.
voidinit(PortletConfig config)
Called by the portlet container to indicate to a portlet that the portlet is being placed into service.
voidinit()
A convenience method which can be overridden so that there's no need to call super.init(config).
voidprocessAction(ActionRequest request, ActionResponse response)
Called by the portlet container to allow the portlet to process an action request.
voidrender(RenderRequest request, RenderResponse response)
The default implementation of this method sets the title using the getTitle method and invokes the doDispatch method.

Field Detail

config

private transient PortletConfig config

Constructor Detail

GenericPortlet

public GenericPortlet()
Does nothing.

Method Detail

destroy

public void destroy()
Called by the portlet container to indicate to a portlet that the portlet is being taken out of service.

The default implementation does nothing.

doDispatch

protected void doDispatch(RenderRequest request, RenderResponse response)
The default implementation of this method routes the render request to a set of helper methods depending on the current portlet mode the portlet is currently in. These methods are:

If the window state of this portlet is minimized, this method does not invoke any of the portlet mode rendering methods.

For handling custom portlet modes the portlet should override this method.

Parameters: request the render request response the render response

Throws: PortletException if the portlet cannot fulfilling the request UnavailableException if the portlet is unavailable to perform render at this time PortletSecurityException if the portlet cannot fullfill this request because of security reasons java.io.IOException if the streaming causes an I/O problem

See Also: GenericPortlet GenericPortlet GenericPortlet

doEdit

protected void doEdit(RenderRequest request, RenderResponse response)
Helper method to serve up the edit mode.

The default implementation throws an exception.

Parameters: request the portlet request response the render response

Throws: PortletException if the portlet cannot fulfilling the request UnavailableException if the portlet is unavailable to perform render at this time PortletSecurityException if the portlet cannot fullfill this request because of security reasons java.io.IOException if the streaming causes an I/O problem

doHelp

protected void doHelp(RenderRequest request, RenderResponse response)
Helper method to serve up the help mode.

The default implementation throws an exception.

Parameters: request the portlet request response the render response

Throws: PortletException if the portlet cannot fulfilling the request UnavailableException if the portlet is unavailable to perform render at this time PortletSecurityException if the portlet cannot fullfill this request because of security reasons java.io.IOException if the streaming causes an I/O problem

doView

protected void doView(RenderRequest request, RenderResponse response)
Helper method to serve up the mandatory view mode.

The default implementation throws an exception.

Parameters: request the portlet request response the render response

Throws: PortletException if the portlet cannot fulfilling the request UnavailableException if the portlet is unavailable to perform render at this time PortletSecurityException if the portlet cannot fullfill this request because of security reasons java.io.IOException if the streaming causes an I/O problem

getInitParameter

public String getInitParameter(String name)
Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.

Parameters: name a String specifying the name of the initialization parameter

Returns: a String containing the value of the initialization parameter

Throws: java.lang.IllegalArgumentException if name is null.

getInitParameterNames

public Enumeration getInitParameterNames()
Returns the names of the portlet initialization parameters as an Enumeration of String objects, or an empty Enumeration if the portlet has no initialization parameters.

Returns: an Enumeration of String objects containing the names of the portlet initialization parameters, or an empty Enumeration if the portlet has no initialization parameters.

getPortletConfig

public PortletConfig getPortletConfig()
Returns the PortletConfig object of this portlet.

Returns: the PortletConfig object of this portlet

getPortletContext

public PortletContext getPortletContext()
Returns the PortletContext of the portlet application the portlet is in.

Returns: the portlet application context

getPortletName

public String getPortletName()
Returns the name of this portlet.

Returns: the portlet name

See Also: getPortletName

getResourceBundle

public ResourceBundle getResourceBundle(Locale locale)
Gets the resource bundle for the given locale based on the resource bundle defined in the deployment descriptor with resource-bundle tag or the inlined resources defined in the deployment descriptor.

Returns: the resource bundle for the given locale

getTitle

protected String getTitle(RenderRequest request)
Used by the render method to get the title.

The default implementation gets the title from the ResourceBundle of the PortletConfig of the portlet. The title is retrieved using the 'javax.portlet.title' resource name.

Portlets can overwrite this method to provide dynamic titles (e.g. based on locale, client, and session information). Examples are:

Returns: the portlet title for this window

init

public void init(PortletConfig config)
Called by the portlet container to indicate to a portlet that the portlet is being placed into service.

The default implementation just stores the PortletConfig object.

The portlet container calls the init method exactly once after instantiating the portlet. The init method must complete successfully before the portlet can receive any requests.

The portlet container cannot place the portlet into service if the init method does one of the following:

  1. it throws a PortletException
  2. it does not return within a time period defined by the Web server

Parameters: config a PortletConfig object containing the portlet configuration and initialization parameters

Throws: PortletException if an exception has occurred that interferes with the portlet normal operation. UnavailableException if the portlet cannot perform the initialization at this time.

init

public void init()
A convenience method which can be overridden so that there's no need to call super.init(config).

Instead of overriding init, simply override this method and it will be called by GenericPortlet.init(PortletConfig config). The PortletConfig object can still be retrieved via GenericPortlet.

Throws: PortletException if an exception has occurred that interferes with the portlet normal operation. UnavailableException if the portlet is unavailable to perform init

processAction

public void processAction(ActionRequest request, ActionResponse response)
Called by the portlet container to allow the portlet to process an action request. This method is called if the client request was originated by a URL created (by the portlet) with the RenderResponse.createActionURL() method.

The default implementation throws an exception.

Parameters: request the action request response the action response

Throws: PortletException if the portlet cannot fulfilling the request UnavailableException if the portlet is unavailable to process the action at this time PortletSecurityException if the portlet cannot fullfill this request because of security reasons java.io.IOException if the streaming causes an I/O problem

render

public void render(RenderRequest request, RenderResponse response)
The default implementation of this method sets the title using the getTitle method and invokes the doDispatch method.

Parameters: request the render request response the render response

Throws: PortletException if the portlet cannot fulfilling the request UnavailableException if the portlet is unavailable to perform render at this time PortletSecurityException if the portlet cannot fullfill this request because of security reasons java.io.IOException if the streaming causes an I/O problem