3.1.1.1.1. Portlet class

Below is the Java source:

package org.gatein.portal.examples.portlets;

 
import java.io.IOException;
import java.io.PrintWriter;
 
import javax.portlet.GenericPortlet;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
  (1)
 public class SimplestHelloWorldPortlet extends GenericPortlet
{ (2)
   public void doView(RenderRequest request,  (3)
                       RenderResponse response) throws IOException
   { (4)
      PrintWriter writer = response.getWriter();
      writer.write("Hello World !"); (5)
      writer.close();
   }
}

1

All portlets must implement the javax.portlet.Portlet interface. The portlet API provides a convenient implementation of this interface.

The javax.portlet.Portlet interface uses the javax.portlet.GenericPortlet class which implements the Portlet render method to dispatch to abstract mode-specific methods. This makes it easier to support the standard portlet modes.

Portlet render also provides a default implementation for the processAction, init and destroy methods. It is recommended to extend GenericPortlet for most cases.

2

If only the view mode is required, only the doView method needs to be implemented. The GenericPortletrender implementation calls our implementation when the view mode is requested.

3

Use the RenderResponse to obtain a writer to be used to produce content.

4

Write the markup to display.

5

Close the writer.

Markup Fragments

Portlets are responsible for generating markup fragments, as they are included on a page and are surrounded by other portlets. This means that a portlet must not output any markup that is not valid in a <body> element.

Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus