Documentation‎ > ‎Portlets‎ > ‎

Using Public Render Parameters

Sample code

This article provides sample codes for two portlets located in separate WAR files that use public render parameters to share data. The value of identifier subelement of public-render-parameter is the key name that portlets neeeds to use to find the value of shared data. If a form is submitted from any of the portlet, other portlet receives data and displays the value.

1. The following is first  portlet's portlet.xml. Notice highlighted xml element which defines public render parameter that it is trying to share.

<?xml version='1.0' encoding='UTF-8' ?>
<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' version='2.0'>
    <portlet>
        <description>PublicRender1</description>
        <portlet-name>PublicRender1</portlet-name>
        <display-name>PublicRender1</display-name>
        <portlet-class>com.softwareorbit.publicrender1.PublicRender1</portlet-class>
        <expiration-cache>0</expiration-cache>
        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>VIEW</portlet-mode>
            <portlet-mode>EDIT</portlet-mode>
            <portlet-mode>HELP</portlet-mode>
        </supports>
        <resource-bundle>com.softwareorbit.publicrender1.messages</resource-bundle>
        <portlet-info>
            <title>PublicRender1</title>
            <short-title>PublicRender1</short-title>
        </portlet-info>
        <supported-public-render-parameter>zipcode</supported-public-render-parameter>
    </portlet>
    <public-render-parameter xmlns:x='http://softwareorbit.com'>
        <identifier>zipcode</identifier>
        <qname>x:zipCodePublicParam</qname>
    </public-render-parameter>
</portlet-app>


2. The java code for the first portlet which sets render parameter using the data it received from form submission

public class PublicRender1 extends GenericPortlet {

    public void processAction(ActionRequest request, ActionResponse response) throws PortletException,IOException {
        response.setRenderParameter("zipcode", request.getParameter("zipcode"));
    }
...
}


3. The view jsp of first portlet which displays form as well as received parameter from previous form submission or data it received from form submission from second portlet.

<h3>Enter City code </h3>
<form method="post" action="<portlet:actionURL></portlet:actionURL>"                 class="cssform">
<p>
<label>  Zip code </label><input type="text" name="zipcode" value=""/>
</p>

<p>
<label>&nbsp;</label>
<input type="submit" value="Submit" />
</p>
</form>
<h3> Current value of zip code </h3>
Zip code <%= renderRequest.getParameter("zipcode") %><p>


4.  The following is second portlet's portlet.xml. Notice highlighted xml element which defines public render parameter that it is trying to share.

<?xml version='1.0' encoding='UTF-8' ?>
<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' version='2.0'>
    <portlet>
        <description>PublicRender2</description>
        <portlet-name>PublicRender2</portlet-name>
        <display-name>PublicRender2</display-name>
        <portlet-class>com.softwareorbit.publicrender2.PublicRender2</portlet-class>
        <expiration-cache>0</expiration-cache>
        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>VIEW</portlet-mode>
            <portlet-mode>EDIT</portlet-mode>
            <portlet-mode>HELP</portlet-mode>
        </supports>
        <resource-bundle>com.softwareorbit.publicrender2.messages</resource-bundle>
        <portlet-info>
            <title>PublicRender2</title>
            <short-title>PublicRender2</short-title>
        </portlet-info>
        <supported-public-render-parameter>zipcode</supported-public-render-parameter>
    </portlet>
    <public-render-parameter xmlns:x='http://softwareorbit.com'>
        <identifier>zipcode</identifier>
        <qname>x:zipCodePublicParam</qname>
    </public-render-parameter>
</portlet-app>


5. The java code for the second portlet which sets render parameter using the data it received from form submission

public class PublicRender2 extends GenericPortlet {

    public void processAction(ActionRequest request, ActionResponse response) throws PortletException,IOException {
    response.setRenderParameter("zipcode", request.getParameter("zipcode"));
    }
..
}


6. The view jsp of second portlet which displays form as well as received parameter from previous form submission or data it received from form submission from first portlet.

<h3>Enter City code</h3>

<form method="post" action="<portlet:actionURL></portlet:actionURL>"                 class="cssform">
<p>
<label>  Zip code </label><input type="text" name="zipcode" value=""/>
</p>

<p>
<label>&nbsp;</label>
<input type="submit" value="Submit" />
</p>
</form>
<h3> Current value of zip code </h3>
Zip code <%= renderRequest.getParameter("zipcode") %><p>


Comments