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;
public class SimplestHelloWorldPortlet extends GenericPortlet
{
public void doView(RenderRequest request,
RenderResponse response) throws IOException
{
PrintWriter writer = response.getWriter();
writer.write("Hello World !");
writer.close();
}
}
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. | |
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. | |
Use the RenderResponse to obtain a writer to be used to produce content. | |
Write the markup to display. | |
Close the writer. |
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.