Jetspeed Simple Portlet Guide

This guide provides a tutorial for creating a very simple portlet. Portlets developers should follow the steps below.

1. The Portlet Class

Create the file Simplest.java in a directory called simplest/WEB-INF/classes:

public class Simplest extends javax.portlet.GenericPortlet
{
    public void doView(javax.portlet.RenderRequest request, javax.portlet.RenderResponse response)
                throws javax.portlet.PortletException, java.io.IOException
    {
            response.setContentType("text/html");
            response.getWriter().println("A very simple portlet.");
    }
}
				

Compile the class using the command,

javac -cp $CATALINA_HOME/shared/lib/portlet-api-1.0.jar Simplest.java
				

2. The portlet.xml

Create the file portlet.xml in the simplest/WEB-INF directory.

<?xml version="1.0" encoding="UTF-8"?>
<portlet-app id="simplest" version="1.0">
  <portlet id="Simplest">
    <portlet-name>Simplest</portlet-name>
    <display-name>Simple Display Name</display-name>
    <portlet-class>Simplest</portlet-class>
    <supports>
      <mime-type>text/html</mime-type>
      <portlet-mode>VIEW</portlet-mode>
    </supports>
    <supported-locale>en</supported-locale>
    <portlet-info>
      <title>Simple Title</title>
      <short-title>The world's simplest portlet</short-title>
    </portlet-info>
  </portlet>
</portlet-app>
			

3. The web.xml

Create the file web.xml in the simplest WEB-INF directory.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
                         "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
  <display-name>Simplest</display-name>
  <description>The world's simplest portlet</description>
</web-app>
			

4. The WAR file

From the directory simplest combine the files above into a war file using the command,

jar cvf ../simplest.war .
			

5. Deploy the WAR file

Copy the war file to $CATALINA_HOME/webapps/jetspeed/WEB-INF/deploy. Jetspeed-2 will deploy the webapp.

6. The PSML

Create the file simplest.psml and copy it to the portal pages directory of your Jetspeed Portal, $CATALINA_HOME/pages/.

Note: If you have different portal pages directory path set by psml.pages.path property in Jetspeed Properties, please use the portal pages directory.

The portlet-app id and the portlet-name are combined to identify the portlet fragment. Alternatively one can use the portlet chooser by clicking on the edit page icon. Your user must have the permission to edit pages. The user admin password admin has permission to edit all pages. The user user password user has permission to edit the [USER 004] PSML Page. And by default Jetspeed-2 allows newly registered users to add portlets and customize their home page.

<?xml version="1.0" encoding="UTF-8"?> 
 <page> 
  <defaults
     skin="orange"
     layout-decorator="tigris"
     portlet-decorator="tigris"
  />
  <title>The simplest portlet in the world</title>
  <metadata name="title" xml:lang="fr">La plus simple portlet du monde</metadata>

  <fragment id="simplest" type="layout" name="jetspeed-layouts::VelocityTwoColumns">
    <fragment id="simplest-1" type="portlet" name="simplest::Simplest">
      <property layout="TwoColumns" name="row" value="0" />
      <property layout="TwoColumns" name="column" value="0" />
    </fragment>
  </fragment>

  <security-constraints>
    <security-constraints-ref>public-view</security-constraints-ref>
  </security-constraints>
</page>
			
Test the portlet using the simplest.psml in your browser.