Skip to main content link. Accesskey S
  • Anonymous
  • Log on
  • Help
  • IBM logo
  • IBM Connections wiki
  • All Wikis
  • Home
  • Community Articles
  • Product Documentation
  • Learning Center


Search

Advanced Search

Categories

Tag Cloud

  • 1.0
  • 1.0.x
  • 2.0
  • 2.0.1
  • 2.0.1.1
  • 2.0_media
  • 2.5
  • 2.5_deployment
  • 2.5_media
  • 2.5_performance
  • 3
  • 3.0
  • 3.0.1
  • 3.0.1_media
  • 3.0_media
  • 3_deployment
  • 8.1.1
  • 8.2
  • activities
  • administrators
  • api
  • best_practices
  • blogs
  • bookmarks
  • business_card
  • cluster
  • communities
  • community
  • community_manager
  • connections
  • connections_3
  • connections_301
  • customization
  • customize
  • customizing
  • demos
  • deploying
  • deployment
  • deployments
  • developers
  • dogear
  • Domino
  • Edge server
  • education
  • error messages
  • files
  • forums
  • getting_started
  • Help
  • home
  • home_page
  • homepage
  • how-to
  • HTTP server
  • ibm
  • index
  • installation
  • integration
  • iOS
  • ipad
  • iWidget
  • J2EE
  • javadoc
  • lc3.0
  • learning
  • lotus-connections
  • mml
  • mobile
  • Notes
  • performance
  • person_card
  • Portal
  • portlet
  • portlet_factory
  • profiles
  • proxy server
  • quickr
  • Redbooks
  • rest
  • reverse proxy server
  • Sametime
  • scenarios
  • search
  • security
  • self-paced
  • SSO
  • tags
  • test_infrastructure
  • troubleshooting
  • tuning
  • video
  • VideoFest
  • videos
  • WAI
  • WAS
  • web_seminar
  • WebAppIntegrator
  • WebSphere
  • widgets
  • wikis
InformationInformation
You are currently viewing machine translated content. IBM translation might be available. Click IBM Translated Product Documentation to see what is available.X


Home > IBM Redbooks: Customizing Lotus Connections 2.0 > 2.3.5 Using Dojo and iWidget iContext to request data
Rate this article 1 starRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

2.3.5 Using Dojo and iWidget iContext to request data 

expanded Abstract
collapsed Abstract
No abstract provided.
Back to parent topic 2.3 Developing widgets for the Lotus Connections home page

Performing data requests is probably the ultimate goal of an iWidget for most developers. We waited to address this topic after the other topics so that we already have the Dojo framework included to make data requests simple. Dojo provides handy functions for both requesting data and transforming it to what we need. While these functions can be replaced with standard JaveScript methods, it is easier to document the practice here in this manner than to spend time explaining the particulars of xmlHTTPRequest objects for different browsers.

The following code shows the XML descriptor from our previous example.

<iw:iwidget name="helloWorld"
     xmlns:iw="http://www.ibm.com/xmlns/prod/iWidget"
        iScope="helloWorld">
<
iw:resource uri="servername/helloworld/helloworldfunctions.js" /

 


 
 

<
/iw:itemSet
 

<
iw:content mode="view"
 
   
  <
![CDATA[
     <div id="helloWorld"/
 
   
  ]]
 

<
/iw:content
 
</iw:iwidget
 
 

This code has a minor change to it in the iw:itemSet section, which provides the ability to pass name-value pairs to the iContext object when it is created. Wherever we have access to the iContext object, we can use it to get the values from the iWidget XML descriptor file. Inside each iw:itemSet, there is an iw:item with an ID (name) and a value. An iWidget descriptor file can have multiple iw:itemSets, and each iw:itemSet can have multiple iw:items. To refer to a particular iw:itemSet through the iContext object, we use iContext.getItemSet(id). This method returns a reference to the particular item set with the ID that is passed in. To get the value of an iw:item in the iw:itemSet, use the getItemValue(id) method on the object containing the reference returned from the iContext.getItemSet(id). In the previous example, we used the iw:itemSet to hold various URLs from which we want to fetch data. Each iw:item is a URL that provides a feed of information.

Due to the security model imposed by browsers, it is not possible to request data from an outside source. This method is called cross site scripting (XSS) and is considered a huge security vulnerability. If a JavaScript function tries to request data from a domain that it was not loaded from, then that request is stopped. To get around this, the iWidget framework provides a function that rewrites a URI to go through an intermediate proxy if needed. If the framework is part of an application that provides or allows data request to be proxied, then this function rewrites the URI to something that allows the request to happen. In the case of Lotus Connections, there is a configurable secure proxy that allows for data r equests. The administrator has control over the domains from which the data can be requested in order to increase security. To rewrite the URI from which you want to request data, pass it to the iContext.io.rewriteURI(uri) method.

The following code example shows an iw:itemSet that is accessed to get a list of URLs from which to request data.

dojo.provide('DojoHello.helloWorld');

the declaration of our dojo widget
dojo.declare("DojoHello.helloWorld",
     [dijit._Widget,dijit._Templated], {
 
a holder for the passed in iContext object
  iContext: null,
  string for our HTML template
  templateString: "

",
 
constructor for the dojo widget
  postCreate: function() {
      get a uri from our itemsets
     var items = this.iContext.getItemSet('urls');
     var location = items.getItemValue('url1');
     
transform the location
     var nLocation = iContext.io.rewriteURI(location);
      create dojo xhr request object
     var bindArgs = { handleAs:text,
                      url:nLocation,
                      timeout:5000
                    };
     
create a GET request for the data
     var req = dojo.xhrGet(bindArgs);
      add a callback function to handle
     
the returned data
     req.addCallback(this,"result");
  },
  this method handles the data
 
returned by our GET request
  result: function(data,evt) {
      append data to the dom
     this.resultContainer.innerHTML=data;
  }
});

In this example, one URL is transformed from what was originally stored in the iw:item to an accessible URI using the iContext.io.rewriteURI(uri) method. The text that is returned by the request is appended to the DOM, in the template of the Dojo widget itself. We use the Dojo.xhrGet method to request the data in this example because of the simplicity of making xmlHTTPRequests compared to using pure javascript. The iWidget 1.0 specification documents a method to make data requests like this, called iContext.io.request(verb,uri,callback,message,header), but it has not been implemented in the 2.0 version of the Lotus Connections iWidget framework.

Usually the data returned by a request would be transformed or interpreted into something more meaningful, such as a visual representation in the case of graph data. Indeed, the data itself can be used to create HTML that is inserted into the widget template itself. With the ability to request data from a Web-based data source, the scope for what an iWidget can represent is massive.

Back to parent topic 2.3 Developing widgets for the Lotus Connections Homepage
Previous topic 2.3.4 Using Dojo widgets inside an iWidget

(Edited by DW)


expanded Article information
collapsed Article information
Category:
IBM Redbooks: Customizing Lotus Connections 2.0
Tags:

This Version: Version 8 June 18, 2009 11:46:55 AM by Jennifer Heins  IBMer

expanded Attachments (0)
collapsed Attachments (0)

 


expanded Versions (8)
collapsed Versions (8)
Version Comparison     
Version Date Changed by               Summary of changes
This version (8) Jun 18, 2009 11:46:55 AM Jennifer Heins  
7 Jan 7, 2009 5:37:52 PM Mike Ebbers  
6 Dec 19, 2008 2:23:53 PM Debbie Willmschen  
5 Nov 8, 2008 4:10:10 PM Mike Ebbers  
4 Sep 5, 2008 6:15:56 AM Jamie J O'Leary  
3 Sep 5, 2008 6:15:14 AM Jamie J O'Leary  
2 Sep 4, 2008 5:47:25 AM Jamie J O'Leary  
1 Sep 4, 2008 5:44:03 AM Jamie J O'Leary  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedSubscribe to RSSHelpAbout
  • All Lotus and WebSphere Portal wikis
  • IBM developerWorks
  • IBM Software support
  • IBM Social Business User Experience Blog
  • IBMSocialBizUX on Twitter
  • IBMSocialBizUX on Facebook
  • Lotus product forums
  • IBM Social Business UX blog
  • IBM Collaboration Solutions
  • Recently added feedRecently added
  • Recently edited feedRecently edited
  • Recently added comments feedRecently Added Comments
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Contact IBM
  • IBM Terms of use
  • Wiki terms of use