Public Render Parameter

The JSR 286 specification introduces concept of Public Render paramter which are same as the render paramter before with a differnece that they can be shared across portlets. Your portlet code for setting render parameter in the URL and reading it remains same, only difference is you declare a render parameter in the portlet.xml and then they are shared across different portlets

I built two sample portlet one is WeatherPortlet and other is MapPortlet, they do nothing but set zip as render parameter and read zip parameter and display it in view mode, this is how my WeatherPorltet looks like

public class WeatherPortlet extends GenericPortlet{
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
System.out.println("Entering WeatherPortlet.doView()");
response.setContentType("text/html");
response.getWriter().println("Value of zip render parameter " +

request.getParameter("zip"));
PortletURL sfoWeather = response.createRenderURL();
sfoWeather.setParameter("zip", "94101");
response.getWriter().println("<a href='"+ sfoWeather.toString()+"'>SFO</a>");

PortletURL puneWeather = response.createRenderURL();
puneWeather.setParameter("zip", "411007");
response.getWriter().println("<a href='"+
puneWeather.toString()+"'>Pune</a>");
System.out.println("Exiting WeatherPortlet.doView()");
}
}


The MapPortlet is same as that of the WeatherPortlet. Now the next part is in the portlet.xml i declare zip as public render parameter and now if i set zip parameter in map it gets available to weather and other way round


<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
version="2.0" 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">
<portlet>
<portlet-name>WeatherPortlet</portlet-name>
<display-name>Weather Portlet</display-name>
<portlet-class>com.webspherenotes.jsr286.WeatherPortlet</portlet-class>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>Weather Portlet</title>
<short-title>Weather Portlet</short-title>
<keywords>WeatherPortlet</keywords>
</portlet-info>
<supported-public-render-parameter>zip</supported-public-render-parameter>
</portlet>
<portlet>
<portlet-name>MapPortlet</portlet-name>
<display-name>MapPortlet Portlet</display-name>
<portlet-class>com.webspherenotes.jsr286.MapPortlet</portlet-class>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>MapPortlet Portlet</title>
<short-title>MapPortlet Portlet</short-title>
<keywords>MapPortletPortlet</keywords>
</portlet-info>
<supported-public-render-parameter>zip</supported-public-render-parameter>
</portlet>

<public-render-parameter>
<identifier>zip</identifier>
<qname xmlns:x="http://webspherenotes.com/params">x:zip</qname>
</public-render-parameter>

</portlet-app>


In WebSphere once you set zip render parameter it remains in the URL until you logout and login again, if you add the Weather and Map portlet on different pages then zip code set on one page is available on other

2 comments:

  1. Hi,
    Can you please tell what is the scope of public render parameter? Is it session scope or request scope?

    ReplyDelete