Setting Portlet Titles at Runtime

This document shows how to set the title of your portlet at runtime. Jetspeed has some special requirements for setting the portlet title at runtime. We demonstrate the configuration requirements, and then how to set the title in your Java portlet code.

Registry

In the portlet registry, declare your portlet:

<registry>
	<portlet-entry name="HelloTitle" hidden="false" type="ref" parent="GenericMVCPortlet" application="false">
		<meta-info>
			<title>HelloTitle</title>
			<description>Simple JSP and Title Portlet Example</description>
		</meta-info>
		<parameter name="template" value="title.jsp" hidden="true"/>
	    <parameter name="viewtype" value="BufferedJSP" hidden="true"/>		
		<parameter name="action" value="portlets.HelloTitleAction" hidden="true"/>		 
		<media-type ref="html"/>
		<category>demo</category>
		<category>jsp.demo</category>
	</portlet-entry>

You must make sure that the parent portlet is GenericMVCPortlet or a derivitive portlet.

parent="GenericMVCPortlet"

The view type must be set to BufferedJSP:

   <parameter name="viewtype" value="BufferedJSP" hidden="true"/>		

Portlet

Setting the portlet title at runtime is done in your portlet code, from an MVC action, buildNormalContext, or the portlet's getContent() methods. Here is an example of setting the title in a portlet actions buildNormalContextGeneric method.

public class HelloTitleAction extends GenericMVCAction
{
    protected void buildNormalContext(Portlet portlet, Context context, RunData data)
        throws Exception
    {
        portlet.setTitle("Here we go " + new Date(), data);        
        super.buildNormalContext(portlet, context, data);
    }
}

Note again, we must derive from the MVC portlet framework. Here we extend GenericMVCAction:

public class HelloTitleAction extends GenericMVCAction

Remember to use the new signature, as the single parameter signature of setTitle does not work!

        portlet.setTitle("Here we go " + new Date(), data);

PSML

Make sure to have a PSML entry that uses the BufferredTitlePortletControl as this is a requirement. (This control can also be selected in the portlet customizer)

        <entry id="P-103f31759e9-10001" parent="HelloTitle">
            <metainfo>
                <title>Here we go Wed May 18 20:55:45 PDT 2005</title>
            </metainfo>
            <layout position="-1" size="-1">
                <property name="column" value="0"/>
                <property name="row" value="0"/>
            </layout>
            <control name="BufferredTitlePortletControl"/>
        </entry>    

Configuration

To make the the buffered title control the default for all portlets, set the following property in your JetspeedResources.properties.merge (or my.properties):

services.PortalToolkit.default.control=BufferredTitlePortletControl