Saturday 17 September 2011

UserProfile Widget in Websphere portal server

getUserProfile() method of icontext returns user profile information similar to PUMA api.In this example,on view mode,user information is displayed

UserProfile.xml
<?xml version="1.0" encoding="UTF-8" ?>
<iw:iwidget id="UserProfileWidget" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:iw="http://www.ibm.com/xmlns/prod/iWidget"
supportedModes="view" lang="en" iScope="UserProfileWidgetScope">
<iw:resource src="UserProfileWidget.js" id="UserProfile" />
<iw:content mode="view">
            <![CDATA[
            <div>UserProfile are:</div>
            <div id="userdetail">
           
            </div>
           
            ]]>
</iw:content>

</iw:iwidget>


UserProfileWidget.js

dojo.declare("UserProfileWidgetScope", 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() {
        var attrs=this.iContext.getUserProfile();
         var names=attrs.getAllNames();
         var i=0;
         var element=this.iContext.getElementById("userdetail");
         var selectedValue = "<div><table border='1'>";
         for (i;i<names.length; i++)
         {
             selectedValue += "<tr><td>"+names[i] + ": </td><td>"+ attrs.getItemValue(names[i]) + "</td></tr>";
         }
          selectedValue+="</table></div>";
          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) {
     }
});

ScreenShot


Click here to download

No comments:

Post a Comment