Showing posts with label enablerapi. Show all posts
Showing posts with label enablerapi. Show all posts

Code generated by client model init tags

If you want to use the Enabler API in your portlet then you will have to include following code at the top of the JSP


<%@taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portlet-client-model"
prefix="portlet-client-model"%>

<portlet-client-model:init>
<portlet-client-model:require module="ibm.portal.xml.*" />
<portlet-client-model:require module="ibm.portal.portlet.*" />
</portlet-client-model:init>


These JSP tags generate following code into your markup

<script>
if(typeof dojo=='undefined') {
document.writeln("<scr"+"ipt src='/wps/themes/dojo/portal_dojo/dojo/dojo.js' ></scr"+"ipt>");
}
</script>
<script>
dojo.require('ibm.portal.xml.xpath');
dojo.require('ibm.portal.xml.xslt');
</script>
<script>
dojo.require('ibm.portal.portlet.portlet');
</script>
<script>
if(typeof(ibmPortalConfig) == "undefined") {
ibmPortalConfig = {contentHandlerURI: "wsrp_rewrite"};
} else if(!ibmPortalConfig["contentHandlerURI"]) {
ibmPortalConfig["contentHandlerURI"] = "wsrp_rewrite";
}
</script>
<div id="com.ibm.wps.web2.portlet.root.Z7_OGFLMKG100AE00IQD0B8FL3042"
style="display: none;">
http://192.168.117.132:10039/wps/mycontenthandler/!ut/p/digest!Mm2hqcemQRtdiuTGl0RuBg/pm/oid:--portletwindowid--@oid:Z6_OGFLMKG100F610IAJQLHQ800G1
</div>
<div id="com.ibm.wps.web2.portlet.preferences.Z7_OGFLMKG100AE00IQD0B8FL3042" style="display: none;"
pageid="Z6_OGFLMKG100F610IAJQLHQ800G1" configid="Z3_OGFLMKG100AE00IQD0B8FL3081" editdefaultsid="Z5_OGFLMKG100AE00IQD0B8FL3046">
</div>
<div id="com.ibm.wps.web2.portlet.user.Z7_OGFLMKG100AE00IQD0B8FL3042" style="display: none;">
http://192.168.117.132:10039/wps/mycontenthandler/!ut/p/digest!Mm2hqcemQRtdiuTGl0RuBg/um/secure/currentuser/profile?expandRefs=true
</div>


The code takes care of first including dojo on page, if its not loaded already then it includes dojo related classes and then it generates couple of hidden div's that has values of portlet Window Id and page id. Then it generates URls which can be used for getting ATOM feed
http://192.168.117.132:10039/wps/mycontenthandler/!ut/p/digest!Mm2hqcemQRtdiuTGl0RuBg/pm/oid:Z7_OGFLMKG100AE00IQD0B8FL3042@oid:Z6_OGFLMKG100F610IAJQLHQ800G1 url can be used for getting ATOM feed for the current portlet and the http://192.168.117.132:10039/wps/mycontenthandler/!ut/p/digest!Mm2hqcemQRtdiuTGl0RuBg/um/secure/currentuser/profile?expandRefs=true URL can be used for getting ATOM feed for the current user's profile

What is enabler API

WebSphere Portal, has introduced Enabler API in Version 7.0, The Enabler API is replacement of Client Side API that was part of the 6.x version. The Enabler API allows you to do following things on client side


  • Manipulate portlet preferences

  • Manipulate user profile

  • Manipulate portlet state

    • Portlet Mode

    • Window State





The Enabler API provides functions that are equivalent to the Portlet client side API and there is one set of functions that can be used from iWidget and other set that can be used from portlet code.

Ex. In WPS 6.0 this is how we use to set portlet preferences

var _portletWindow = new ibm.portal.portlet.PortletWindow("<%=portletWindowID%>");
_portletWindow.getPortletPreferences(setPreference);
function setPreference(){
portletPrefs.setValue(preferenceName,preferenceValue);
portletWindow.setPortletPreferences(portletPrefs,printPreferencesCallback);
}


But now you will have to use code like this inside the Portlet

var navigationModel = com.ibm.mashups.enabler.navigation.Factory.getNavigationModel();
var selectedNode = navigationModel.find().start();
var layoutModel = navigationModel.getLayoutModel(selectedNode);
var layoutControl = layoutModel.find().start();
var widgetInstance = widgetModel.getWidgetWindow(layoutControl).start();

// set preferences
var modifiablePreferences = widgetModel.getHierarchicalPreferences(widgetInstance).start();
modifiablePreferences.setValues(key, values);

// commit
this.widgetModel.commit().start();


This is the code that you can use inside the iWidget

var result = iContext.getiWidgetAttributes();
result.setItemValue(itemName, itemValue);


Important Note: IBM deprecates the client side programming model from the previous versions. Although the old model still works, developers are encouraged to write new code to comply with the new Enabler APIs. with the old API.