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.


In the portlet registry, declare your portlet:

	<portlet-entry name="HelloTitle" hidden="false" type="ref" parent="GenericMVCPortlet" application="false">
			<description>Simple JSP and Title Portlet Example</description>
		<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"/>

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


The view type must be set to BufferedJSP:

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


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);


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">
                <title>Here we go Wed May 18 20:55:45 PDT 2005</title>
            <layout position="-1" size="-1">
                <property name="column" value="0"/>
                <property name="row" value="0"/>
            <control name="BufferredTitlePortletControl"/>


To make the the buffered title control the default for all portlets, set the following property in your (or