Package javax.portlet
Class GenericPortlet
- java.lang.Object
-
- javax.portlet.GenericPortlet
-
- All Implemented Interfaces:
Portlet
public abstract class GenericPortlet extends Object implements Portlet
TheGenericPortletclass provides a default implementation for thePortletinterface. It provides an abstract class to be subclassed to create portlets. A subclass ofGenericPortletshould override at least one method, usually one of the following:- processAction, to handle action requests
- doView, to handle render requests when in VIEW mode
- doEdit, to handle render requests when in EDIT mode
- doHelp, to handle render request when in HELP mode
- init and destroy, to manage resources that are held for the life of the servlet
- Version:
- $Revision: 5441 $
- Author:
- Julien Viet
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedGenericPortlet()Does nothing.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 theeditmode.protected voiddoHelp(RenderRequest request, RenderResponse response)Helper method to serve up thehelpmode.protected voiddoView(RenderRequest request, RenderResponse response)Helper method to serve up the mandatoryviewmode.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 thePortletContextof 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 withresource-bundletag or the inlined resources defined in the deployment descriptor.protected StringgetTitle(RenderRequest request)Used by the render method to get the title.voidinit()A convenience method which can be overridden so that there's no need to callsuper.init(config).voidinit(PortletConfig config)Called by the portlet container to indicate to a portlet that the portlet is being placed into service.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 thegetTitlemethod and invokes thedoDispatchmethod.
-
-
-
Method Detail
-
init
public void init() throws PortletExceptionA convenience method which can be overridden so that there's no need to callsuper.init(config).Instead of overriding
init(PortletConfig), simply override this method and it will be called byGenericPortlet.init(PortletConfig config). ThePortletConfigobject can still be retrieved viagetPortletConfig().- Throws:
PortletException- if an exception has occurred that interferes with the portlet normal operation.UnavailableException- if the portlet is unavailable to perform init
-
getPortletConfig
public PortletConfig getPortletConfig()
Returns the PortletConfig object of this portlet.- Returns:
- the PortletConfig object of this portlet
-
getPortletName
public String getPortletName()
Returns the name of this portlet.- Returns:
- the portlet name
- See Also:
PortletConfig.getPortletName()
-
getPortletContext
public PortletContext getPortletContext()
Returns thePortletContextof the portlet application the portlet is in.- Returns:
- the portlet application context
-
doDispatch
protected void doDispatch(RenderRequest request, RenderResponse response) throws PortletException, PortletSecurityException, IOException
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:doViewfor handlingviewrequestsdoEditfor handlingeditrequestsdoHelpfor handlinghelprequests
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 requestresponse- the render response- Throws:
PortletException- if the portlet cannot fulfilling the requestUnavailableException- if the portlet is unavailable to perform render at this timePortletSecurityException- if the portlet cannot fullfill this request because of security reasonsIOException- if the streaming causes an I/O problem- See Also:
doView(RenderRequest,RenderResponse),doEdit(RenderRequest,RenderResponse),doHelp(RenderRequest,RenderResponse)
-
doView
protected void doView(RenderRequest request, RenderResponse response) throws PortletException, PortletSecurityException, IOException
Helper method to serve up the mandatoryviewmode. The default implementation throws an exception.- Parameters:
request- the portlet requestresponse- the render response- Throws:
PortletException- if the portlet cannot fulfilling the requestUnavailableException- if the portlet is unavailable to perform render at this timePortletSecurityException- if the portlet cannot fullfill this request because of security reasonsIOException- if the streaming causes an I/O problem
-
doHelp
protected void doHelp(RenderRequest request, RenderResponse response) throws PortletException, PortletSecurityException, IOException
Helper method to serve up thehelpmode. The default implementation throws an exception.- Parameters:
request- the portlet requestresponse- the render response- Throws:
PortletException- if the portlet cannot fulfilling the requestUnavailableException- if the portlet is unavailable to perform render at this timePortletSecurityException- if the portlet cannot fullfill this request because of security reasonsIOException- if the streaming causes an I/O problem
-
doEdit
protected void doEdit(RenderRequest request, RenderResponse response) throws PortletException, PortletSecurityException, IOException
Helper method to serve up theeditmode. The default implementation throws an exception.- Parameters:
request- the portlet requestresponse- the render response- Throws:
PortletException- if the portlet cannot fulfilling the requestUnavailableException- if the portlet is unavailable to perform render at this timePortletSecurityException- if the portlet cannot fullfill this request because of security reasonsIOException- if the streaming causes an I/O problem
-
getResourceBundle
public ResourceBundle getResourceBundle(Locale locale)
Gets the resource bundle for the given locale based on the resource bundle defined in the deployment descriptor withresource-bundletag 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:- language-dependant titles for multi-lingual portals
- shorter titles for WAP phones
- the number of messages in a mailbox portlet
- Returns:
- the portlet title for this window
-
getInitParameter
public String getInitParameter(String name) throws IllegalArgumentException
Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.- Parameters:
name- aStringspecifying the name of the initialization parameter- Returns:
- a
Stringcontaining the value of the initialization parameter - Throws:
IllegalArgumentException- if name isnull.
-
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
EnumerationofStringobjects containing the names of the portlet initialization parameters, or an empty Enumeration if the portlet has no initialization parameters.
-
init
public void init(PortletConfig config) throws PortletException
Called by the portlet container to indicate to a portlet that the portlet is being placed into service. The default implementation just stores thePortletConfigobject.The portlet container calls the
initmethod exactly once after instantiating the portlet. Theinitmethod must complete successfully before the portlet can receive any requests.The portlet container cannot place the portlet into service if the
initmethod does one of the following:- it throws a
PortletException - it does not return within a time period defined by the Web server
- Specified by:
initin interfacePortlet- Parameters:
config- aPortletConfigobject 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.
- it throws a
-
processAction
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, PortletSecurityException, IOException
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 theRenderResponse.createActionURL()method. The default implementation throws an exception.- Specified by:
processActionin interfacePortlet- Parameters:
request- the action requestresponse- the action response- Throws:
PortletException- if the portlet cannot fulfilling the requestUnavailableException- if the portlet is unavailable to process the action at this timePortletSecurityException- if the portlet cannot fullfill this request because of security reasonsIOException- if the streaming causes an I/O problem
-
render
public void render(RenderRequest request, RenderResponse response) throws PortletException, PortletSecurityException, IOException
The default implementation of this method sets the title using thegetTitlemethod and invokes thedoDispatchmethod.- Specified by:
renderin interfacePortlet- Parameters:
request- the render requestresponse- the render response- Throws:
PortletException- if the portlet cannot fulfilling the requestUnavailableException- if the portlet is unavailable to perform render at this timePortletSecurityException- if the portlet cannot fullfill this request because of security reasonsIOException- if the streaming causes an I/O problem
-
-