Hello World Portlet

To start with, the very first portlet is the simplest, the obligatory "Hello World", it extends AbstractInstancePortlet. All the code necessary is shown below:


package org.apache.jetspeed.tutorial.portal.portlets;

public class HelloWorldPortlet extends AbstractInstancePortlet
{
    public ConcreteElement getContent (RunData runData)
    {
        return (new StringElement ("Hello World! #" + getID()));
    }
}
}    

When you have compiled this portlet and configured it into the portlet registry, the user can choose the portlet from the list of available portlets when customizing their home page. As you can see, the most important method to override is the getContent() method, which provides the content of your portlet to the response payload. We will cover this method in detail in the section on the Portlet interface.

In future chapters we will discover better methods for generating your content, using the set of MVC portlets provided with the Jetspeed distribution. See tutorials 7 onwards for examples these abstractions where it is not necessary to override the getContent method. For the purpose of learning the very basics of portlet operations, tutorials 5 and 6 will demonstrate how the getContent method works without any MVC abstraction.