Show TOC Start of Content Area

Background documentation Extending the GenericPortlet  Locate the document in its SAP Library structure

The GenericPortletabstract class provides the default functionality and methods for handling render requests. This is an abstract class and its subclass should override at least one of the following methods:

      processAction – to handle action requests

      doView – to handle render requests in VIEW mode

      doEdit – to handle render requests in EDIT mode

      doHelp – to handle render request in HELP mode

      init and destroy – to manage resources held for the lifetime of the servlet

The default implementation of the render() method sets the title specified in the portlet’s deployment descriptor and dispatches the request processing to one of the doView, doEdit, and doHelp methods according to the portlet mode the portlet is currently in.

Example

A simple subclass of the GenericPortlet class will typically override the doView, doEdit, doHelp and getTitle methods instead of the render and doDispatch methods:

import java.io.IOException;

import java.io.PrintWriter;

 

import javax.portlet.GenericPortlet;

import javax.portlet.PortletException;

import javax.portlet.RenderRequest;

import javax.portlet.RenderResponse;

/**

 * HelloWorldPortlet by extendig GenericPortlet

 *

 */

public class HelloWorldPortlet extends GenericPortlet {

  

  /**

   * The doView() method sets the content type of the response - hardcoded to

   * text/html, since the portlet will return simple HTML. Then it obtains

   * the PrintWriter and prints the portlet's content

   */

  public void doView(RenderRequest request, RenderResponse response)

      throws PortletException, IOException {

    response.setContentType("text/html");

    PrintWriter out = response.getWriter();

    out.println("Hello World!");

  }

}

 

  }

 

}

 

 

 

End of Content Area