Public render parameters :- Using these parameters we can share information between portlets . Public render parameters are declared in portlet.xml . Please look at my previous blog for other means of communication between portlets.
Public render parameters allow JSR 286 portlets to share navigational state information. They are specially useful for coordinating the multiple navigation or viewer portlets that display different information items that are all related to the same parameter name. The portal stores all portlet render parameters, including public render parameters, as an encoded part of the current portal URL. Therefore public render parameters are correctly preserved by typical browser navigation actions such as Back button and bookmarking.
For some use cases it can be required to limit parameter sharing. For example, this can apply if you have two pairs of navigator or viewer portlets on two different pages, where each pair should be coordinated, but they should not interfere across pages so that the navigator on the first page does not influence the viewer on the second page. For such cases, the portal allows you to limit the sharing scope for public render parameters on a page basis. The parameter sharing scope for a page is controlled by a page parameter param.sharing.scope. You can set it from the Page Properties view under Advanced options -> I want to set parameters. If you set a value for this page parameter, portlets on the page share their public render parameters only with other portlets on the same page or on pages with the same scope.
If you want to prevent all render parameters used on a given page from being shared with other pages, you can set the parameter param.sharing.scope to the reserved value ibm.portal.sharing.scope.page. This produces the same result as using the unique object ID of the page, as generated internally by the portal, for the value of the param.sharing.scope parameter.
Public render parameters allow JSR 286 portlets to share navigational state information. They are specially useful for coordinating the multiple navigation or viewer portlets that display different information items that are all related to the same parameter name. The portal stores all portlet render parameters, including public render parameters, as an encoded part of the current portal URL. Therefore public render parameters are correctly preserved by typical browser navigation actions such as Back button and bookmarking.
How to control parameter sharing in the portal :-
The portal implements the sharing of parameters by placing them in scopes: Two or more public render parameters from different portlets are mapped to the same data in the portlet URL, if and only if both of the following conditions apply:- The parameters declare the same global name including the namespace.
- The parameters are placed in the same scope.
For some use cases it can be required to limit parameter sharing. For example, this can apply if you have two pairs of navigator or viewer portlets on two different pages, where each pair should be coordinated, but they should not interfere across pages so that the navigator on the first page does not influence the viewer on the second page. For such cases, the portal allows you to limit the sharing scope for public render parameters on a page basis. The parameter sharing scope for a page is controlled by a page parameter param.sharing.scope. You can set it from the Page Properties view under Advanced options -> I want to set parameters. If you set a value for this page parameter, portlets on the page share their public render parameters only with other portlets on the same page or on pages with the same scope.
If you want to prevent all render parameters used on a given page from being shared with other pages, you can set the parameter param.sharing.scope to the reserved value ibm.portal.sharing.scope.page. This produces the same result as using the unique object ID of the page, as generated internally by the portal, for the value of the param.sharing.scope parameter.
Limitations :-
The following are known limitations to public render parameters:- The sharing scope always applies to all parameters of all portlets on a page; you can currently not control sharing of public render parameters at a more granular level than the page level.
Example for public render parameters :-
Step 1 :- We need to create two portlets in a portlet application so that we can set public render parameters from one portlet and access it from other portlet
Step 2 :- Now in portlet.xml we need to create a public render parameter so that we can share data using it.
<public-render-parameter>
<identifier>Global</identifier>
<name>SharedRenderParam</name>
</public-render-parameter>
Step 3 :- Now for remaining two portlets you need to add supported-public-render-parameters tag and final portlet.xml should like below.
<?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" id="com.ibm.explorepublicrenderparams.ExplorePublicRenderParamsPortlet.faff34d494">
<portlet>
<portlet-name>ExplorePublicRenderParams</portlet-name>
<display-name xml:lang="en">ExplorePublicRenderParams</display-name>
<display-name>ExplorePublicRenderParams</display-name>
<portlet-class>com.ibm.explorepublicrenderparams.ExplorePublicRenderParamsPortlet</portlet-class>
<init-param>
<name>wps.markup</name>
<value>html</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<resource-bundle>com.ibm.explorepublicrenderparams.nl.ExplorePublicRenderParamsPortletResource</resource-bundle>
<portlet-info>
<title>ExplorePublicRenderParams</title>
<short-title>ExplorePublicRenderParams</short-title>
<keywords>ExplorePublicRenderParams</keywords>
</portlet-info>
<supported-public-render-parameter>Global</supported-public-render-parameter>
</portlet>
<portlet>
<portlet-name>ExplorePublicRenderParams2</portlet-name>
<display-name xml:lang="en">ExplorePublicRenderParams2</display-name>
<display-name>ExplorePublicRenderParams2</display-name>
<portlet-class>com.ibm.explorepublicrenderparams.ExplorePublicRenderParams2Portlet</portlet-class>
<init-param>
<name>wps.markup</name>
<value>html</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<resource-bundle>com.ibm.explorepublicrenderparams.nl.ExplorePublicRenderParams2PortletResource</resource-bundle>
<portlet-info>
<title>ExplorePublicRenderParams2</title>
<short-title>ExplorePublicRenderParams2</short-title>
<keywords>ExplorePublicRenderParams2</keywords>
</portlet-info>
<supported-public-render-parameter>Global</supported-public-render-parameter>
</portlet>
<default-namespace>http://ExplorePublicRenderParams/</default-namespace>
<public-render-parameter>
<identifier>Global</identifier>
<name>SharedRenderParam</name>
</public-render-parameter>
</portlet-app>
Step4 :- Now we need to set view pages for both of the portlets
ExplorePublicRenderParamsPortlet set view for this portlet :-
<%@page session="false" contentType="text/html" pageEncoding="ISO-8859-1" import="java.util.*,javax.portlet.*,com.ibm.explorepublicrenderparams.*" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portlet-client-model" prefix="portlet-client-model" %>
<portlet:defineObjects/>
<portlet-client-model:init>
<portlet-client-model:require module="ibm.portal.xml.*"/>
<portlet-client-model:require module="ibm.portal.portlet.*"/>
</portlet-client-model:init>
<DIV style="margin: 6px">
<H3 style="margin-bottom: 3px">Welcome!</H3>
Portlet1 sets render parameters if it is already set then value is ${Global} <br/>
<a href="<portlet:actionURL/>">Click to set RenderParam</a>
</DIV>
ExplorePublicRenderParams2Portlet set view for this portlet :-
<%@page session="false" contentType="text/html" pageEncoding="ISO-8859-1" import="java.util.*,javax.portlet.*,com.ibm.explorepublicrenderparams.*" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portlet-client-model" prefix="portlet-client-model" %>
<portlet:defineObjects/>
<portlet-client-model:init>
<portlet-client-model:require module="ibm.portal.xml.*"/>
<portlet-client-model:require module="ibm.portal.portlet.*"/>
</portlet-client-model:init>
<DIV style="margin: 6px">
<H3 style="margin-bottom: 3px">Welcome!</H3>
Portlet2 displays render parameters from Portlet1 so value is ${Global}
</DIV>
Step5:- Output now we will click action link in one portlet then set render parameters and then retrieve it in other portlets in same page.
Now click on link
No comments:
Post a Comment