Sample code for working with User Profiles on the clent side

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" session="false"%><%@taglib
uri="http://java.sun.com/portlet" prefix="portlet"%><%@taglib
uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portlet-client-model"
prefix="portlet-client-model"%><%@taglib
uri="http://java.sun.com/portlet" prefix="portletx"%><portlet-client-model:init>
<portlet-client-model:require module="ibm.portal.xml.*" />
<portlet-client-model:require module="ibm.portal.portlet.*" />
</portlet-client-model:init>
<portlet:defineObjects />
<p>User Profile Sample</p>
<script>
_portletWindow = new ibm.portal.portlet.PortletWindow("<%=portletWindowID%>");
function handleUserProfile(portletWindow, status, userProfile){
console.log("Inside handleUserProfile");
console.log(userProfile);
if (status==ibm.portal.portlet.PortletWindow.STATUS_OK) {
// This is sample of how to get attributes from User Profile
console.log("Preferences.getValue()\n"+ userProfile.getAttribute("uid"));
//Follow these two steps to set attribute
userProfile.setAttribute("displayName","Sunil Patil");
_portletWindow.setUserProfile(userProfile);
}
else {
console.log("error loading feed");
}
}
_portletWindow.getUserProfile(handleUserProfile);
</script>

You can download this sample from here

No comments:

Post a Comment