Jetspeed Simple Velocity Portlet Guide

This guide provides a tutorial for creating a very simple Velocity portlet with one template in the portlet view mode.

1. The Portlet Class

Create the file in a directory called velocity-simplest/WEB-INF/classes:

public class VelocitySimplest extends org.apache.portals.bridges.velocity.GenericVelocityPortlet

    public void doView(javax.portlet.RenderRequest request, javax.portlet.RenderResponse response)
                throws javax.portlet.PortletException,
        super.doView(request, response);

Compile the class in the velocity-simplest/WEB-INF/classes directory using the command,

javac -cp portlet-api-1.0.jar:portals-bridges-velocity-1.0.jar:portals-bridges-common-1.0.jar

2. The portlet.xml

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

<?xml version="1.0" encoding="UTF-8"?>
<portlet-app id="velocitysimplest" version="1.0">
  <portlet id="VelocitySimplest">
    <display-name>Velocity Simplest Display Name</display-name>
      <title>Velocity Simplest Title</title>
      <short-title>Velocity Simplest Short Title</short-title>

3. The web.xml

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

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

  <!-- Define Velocity Servlet -->

  <!-- Map *.vm files to Velocity  -->


4. The View

Create the world.vm file in the velocity-simplest/WEB-INF/view directory. Put whatever content you desire in it. Notice that the template file is defined in the portlet init parameter ViewPage. The objects PortletConfig, RenderRequest, and RenderResponse are automatically placed in the Velocity context for use in Velocity templates. Here is a sample template showing a few of these objects methods and properties.

#set ($MESSAGES = $portletConfig.getResourceBundle($renderRequest.Locale))

5. The Dependency JARs

Copy the commons-beanutils-1.7.0.jar, commons-collections-3.1.jar, commons-digester-1.7.jar, portals-bridges-velocity-1.0.jar, velocity-1.4.jar, and velocity-tools-1.1.jar to the velocity-simplest/WEB-INF/lib directory. IMPORTANT: Do NOT put the portlet-api-1.0.jar in the war file. If you have already built Jetspeed these jars should be in your Maven repository. If so executing these commands in the lib directory will set up the dependencies for you.

ln -s ~/.maven/repository/commons-beanutils/jars/commons-beanutils-1.7.0.jar
ln -s ~/.maven/repository/commons-collections/jars/commons-collections-3.1.jar
ln -s ~/.maven/repository/commons-digester/jars/commons-digester-1.7.jar
ln -s ~/.maven/repository/org.apache.portals.bridges/jars/portals-bridges-velocity-1.0.jar
ln -s ~/.maven/repository/velocity/jars/velocity-1.4.jar
ln -s ~/.maven/repository/velocity-tools/jars/velocity-tools-1.1.jar

6. The WAR file

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

jar cvf ../velocitysimplest.war .

7. Deploy the WAR file

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

8. The PSML

Create the PSML page using the Jetspeed portlet chooser. Login and click 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.