In client side rendering mode, the portlet concept of public render parameters is mapped to the shared item set concept defined in the iWidget specification.
For portlets that do not provide custom iWidget markup this mapping is automatically performed by the portlet wrapper and transparent for the used portlets. Public render parameters are stored in a shared item set called public-render-parameters. iWidgets can access or modify the parameters by accessing this special shared item set. Similarly to the portlet model, iWidgets can access a parameter value by providing the complete qname for the parameter or a local parameter name that is mapped to a full parameter qname in the widget definition xml file.
If the value of a public render parameter is a single String object, the value in the shared item set is of the javascript type string. If the value of a public render parameter is a String array, then the value in the shared item set is a json array that contains the different values.
In this example, public render parameter name in RenderParameter Portlet is shared with RenderParameter Widget
Define Render Parameter Portlet.xml:
<?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.renderparameterportlet.RenderParameterPortlet.a499e19623">
<portlet>
<portlet-name>RenderParameterPortlet</portlet-name>
<display-name xml:lang="en">RenderParameterPortlet</display-name>
<display-name>RenderParameterPortlet</display-name>
<portlet-class>com.ibm.renderparameterportlet.RenderParameterPortlet</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.renderparameterportlet.nl.RenderParameterPortletResource</resource-bundle>
<portlet-info>
<title>RenderParameterPortlet</title>
<short-title>RenderParameterPortlet</short-title>
<keywords>RenderParameterPortlet</keywords>
</portlet-info>
<supported-public-render-parameter>myname</supported-public-render-parameter>
</portlet>
<default-namespace>http://RenderParameterPortlet/</default-namespace>
<public-render-parameter>
<identifier>myname</identifier>
<qname xmlns:x="http://ibm.com/params">x:name</qname>
</public-render-parameter>
</portlet-app>
Support Render Parameter in Portlet
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
if( request.getParameter(FORM_SUBMIT) != null ) {
response.setRenderParameter("myname",request.getParameter(FORM_TEXT));
}
}
Retrieve of Render Parameter in widget
RenderParameterWidget.xml
<?xml version="1.0" encoding="UTF-8" ?>
<iw:iwidget id="RenderParameterWidget" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:iw="http://www.ibm.com/xmlns/prod/iWidget"
supportedModes="view" lang="en" iScope="RenderParameterWidgetScope">
<iw:resource src="RenderParameterWidget.js" id="renderId" />
<iw:itemSet id="public-render-parameters" private="false">
<iw:item id="namevalue" alias="{http://ibm.com/params}name" readOnly="false" />
</iw:itemSet>
<iw:content mode="view">
<![CDATA[
<div>Hello World</div> <div id="displayname"></div>
]]>
</iw:content>
</iw:iwidget>
RenderParameterWidget.js
dojo.declare("RenderParameterWidgetScope", null,{
/*
THE FOLLOWING STUBS ARE EVENT HANDLERS FOR PRE-DEFINED EVENTS.
THEY CAN BE OVERRIDDEN BY SPECIFYING ANOTHER EVENT HANDLER
IN THE <iwidget> ELEMENT OF THE XML
Eg: <iw:iwidget onLoad="myLoadHandler" />
*/
/*
This event signals that the page has finished loading, including any
invocations of requires().
As a simple notification, it carries no predefined payload
*/
onLoad:function() {
},
/*
This event signals that the iWidget is about to be unloaded (commonly
due to a page transition). This notification is intended to allow the
iWidget to store any transient data such that it can
be recovered by future uses of the iWidget
*/
onUnload:function() {
},
/*
This event signals that the mode for the iWidget has changed to VIEW
*/
onView:function() {
if(this.iContext.getShareableItemSet("public-render-parameters",false).getItemValue("namevalue"))
{
var selectedValue=this.iContext.getShareableItemSet("public-render-parameters",false).getItemValue("namevalue");
var element=this.iContext.getElementById("displayname");
element.innerHTML=selectedValue;
}
},
/*
This event signals that the mode for the iWidget has changed to EDIT
*/
onEdit:function() {
},
/*
This event signals that the size for the iWidget has changed
*/
onSizeChanged:function(/*com.ibm.mashups.iwidget.IEvent*/ event) {
var newWidth = event.payload.newWidth;
var newHeight = event.payload.newHeight;
},
/*
This event can be generated by either the iWidget, supplying a new
value for its "navigational state", or by the iContext, signaling
that some user action has changed the iWidget's "navigational state"
to a previously defined value.
*/
onNavStateChanged:function(/*com.ibm.mashups.iwidget.IEvent*/ event) {
}
});
ScreenShots: