concept GenericPortlet class in category java

This is an excerpt from Manning's book Portlets in Action.
A portlet class must implement the javax.portlet.Portlet interface, directly or indirectly. The portlet API has a GenericPortlet abstract class that implements the Portlet interface and provides a default implementation for its methods. Developers will usually subclass the GenericPortlet class and override one or more methods to provide a specific implementation. The HelloWorldPortlet class is an example of a portlet class.
The next section covers the Portlet interface and GenericPortlet class, which are used to create portlets.
The UserRegistrationPortlet class extends the GenericPortlet class and makes use of @RenderMode and @ProcessAction annotations to specify the portlet’s render and action methods. The following code snippet shows the init method:
private String defaultEmail; public void init() { defaultEmail = getPortletConfig().getInitParameter("defaultEmail"); }The init method makes use of the GenericPortlet class’s getInitParameter convenience method to obtain the defaultEmail portlet initialization parameter from the portlet deployment descriptor.
The GenericPortlet class provides a default implementation for all the methods defined in the different lifecycle interfaces (Portlet, ResourceServingPortlet, and EventPortlet), along with convenience methods, making it easy for developers to write their own portlets. There are several benefits of extending the GenericPortlet class to create your own portlet:
GenericPortlet makes use of the Java annotation facility to dispatch requests to the appropriate method. This allows you to give developer-friendly names to your methods so you can recognize them easily. We’ll discuss the annotations available in the GenericPortlet class later in this chapter. Figure 2.9 shows that the GenericPortlet class implements lifecycle interfaces and provides convenience methods. For brevity, not all methods of the GenericPortlet class are shown in the figure.
Figure 2.9. The GenericPortlet abstract class implements the Portlet, EventPortlet, and ResourceServingPortlet interfaces. It provides default implementations of the Portlet interface’s render method, and it dispatches render requests to the doView, doHelp, and doEdit methods, depending upon the portlet’s mode.
![]()