Init Parameters, Attributes and Titles

The Portlet interface allows for you to set two different types of configuration variables for your portlet and its instances. Init Parameters are defined in the registry. Attributes are defined in a PSML file. Init Parameters are associated with all portlets of a given class and are read only. Attributes are associated with only one instance of a portlet class on a given PSML page, and can be modified and persisted. Given our example portlet, we have the Init Parameter named 'version', which is set to the value '1.6'. We also have two instances of the same portlet on our page. Each of these portlets instances have the same parameter defined on the same PSML page, called 'city' with the value of 'Tokyo' and 'Sidney'.

Here is the Init Parameter defined in the registry. Init Parameters can be hidden. This means they will not be displayed in certain areas of the application such as portlet customization:

 <parameter name="version" value="1.6" hidden="false"/>

And the attributes for each portlet instance:

 <entry parent="HelloPortletInterface">
        <parameter name='city' value='Tokyo'/>
    <entry parent="HelloPortletInterface">
        <parameter name='city' value='Sidney'/>

The portlet interface supports working with portlet instances directly using the methods:

getID()        : returns the unique Portlet instance id
getInstance()  : returns the instance associated with this portlet.
getAttribute() : returns a persistent attribute from page storage
setAttribute() : stores an attribute to a persistent page

For accessing read only Init Parameters, you must first get the PortletConfig object for a portlet, and from there you can get the Init Parameters. From the getContent method:

        text.append("Portlet id = " + this.getID());
        text.append("Init Parameter (version): " + 
                     pc.getInitParameter("version", "NOT FOUND!");        
        text.append("Page Attribute (city): " 
                    + this.getAttribute("city", "NOT FOUND!", rundata);

The Jetspeed Portlet customizer only displays Init Parameters in the edit window. Thus the 'city' attribute described above will not show up in the customizer, since it doesn't have an Init Parameter associated with it. The portlet customizer associates Attributes with Init Parameters, and allows you to edit the parameter, but when it is saved, it is saved as an attribute to the current page, and is not saved to the common registry entry.

Lets try customizing the first Hello Portlet Interface portlet:

Press update and we see:

If you want to use the default customizer, it is recommended that all of your parameters be defined in the portlet registry when you deploy your portlets. Also notice that the title was changed. Titles are maintained with the Portlet interface methods getTitle and setTitle.