Sun Java System Portal Server 7.2 Developer's Guide

Public Render Parameters

In Java Portlet Specification 1.0 (JSR 168), the render parameters set in the processAction() method are available only in the render phase of the same portlet. By using the public render parameters feature, the render parameters set in the processAction() method of one portlet are available in render parameters of the other portlets. Using public render parameters instead of events avoids the additional process event call.

To enable coordination of render parameters with other portlets within the same portlet application or across portlet applications, the portlet can declare public render parameters in its deployment descriptor using the public-render-parameter element in the portlet application section. Public render parameters can be viewed and changed by other portlets or components. In the portlet section, each portlet can specify the public render parameters to be shared through the supported-public-render-parameter element. The supported-public-render-parameter element must reference the identifier of a public render parameter defined in the portlet application section in a public-render-parameter element.

ProcedureTo Create Portlets That use the Public Render Parameters

  1. Declare the render parameters to be shared in the portlet.xml file by setting the public render parameters at the portlet application level.


    <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/
                 portlet-app_2_0.xsd"             
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"             
                 xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/
                 portlet-app_2_0.xsd
                 http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
                    
    
    id="myPortletApp" version="2.0">
    	<portlet>
    	...
    	</portlet>
    
    	<public-render-parameter>
    		<identifier>zip-id</identifier>
    		<qname xmlns:x="http://sun.com/params">x:zip</qname>
    	</public-render-parameter>
    
    </portlet-app>
  2. Specify the render parameter that the portlet would like to share in the portlet section.


    <portlet-app_2_0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
    http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
    
    id="myPortletApp" version="2.0"
    <portlet>
    		<description>WeatherPortlet</description>
    		<portlet-name>WeatherPortlet</portlet-name>
    		<display-name>WeatherPortlet</display-name>
    		<portlet-class>com.sun.portal.portlet.WeatherPortlet</portlet-class>
    		<supported-public-render-parameter>zip-id<//supported-public-
       	render-parameter>
    <portlet>
    
    <portlet>
    		<description>MapPortlet</description>
    		<portlet-name>MapPortlet</portlet-name>
    		<display-name>MapPortlet</display-name>
    		<portlet-class>com.sun.portal.portlet.MapPortlet</portlet-class>
    		<supported-public-render-parameter>zip-id<//supported-public-
       	render-parameter>
    <portlet>
    		...
    <portlet-app>
  3. Set the render parameter in the processAction() method by using the defined public render parameter identifier as the key.


    public class WeatherPortlet extends GenericPortlet {
         . . . 
       public void processAction(ActionRequest req, ActionResponse res)
       throws IOException, PortletException {
        . . . 
               res.setRenderParameter("zip-id", zip);
         }
         . . .
    }

Sample Application

The following figure shows the Weather and Map portlets. The Weather portlet sets the zip which is declared as a Public Render Parameter. This parameter is supported by both Weather and Map portlets. Any change in the value of zip by Weather portlet is reflected during the render phase of both weather and map portlets.

Figure 16–2 Sample Application for Public Render Parameter

Sample Application for Public Render Parameter