gi.js
is a library to help integrate DWR with TIBCO GI. It is due for official release with DWR 3.0, however it is reasonably stable now, and will probably only undergo performance tweaking before the official 3.0 release.
Since it doesn't have any dependencies on DWR, it can be used without waiting for an official release. The best place to download it is either via a milestone release of DWR (see the java.net download page), or through the FishEye view of the DWR CVS repository. See this direct link to gi.js.
The toCdfDocument()
function is useful for creating ready made CDF documents from JavaScript objects. It is particularly useful when you have some collection of object on the server, which are converted into a JavaScript array of objects by DWR.
CDF documents are XML documents that conform to the "Common Data Format" to which GI's controls easily bind. You can find out more about CDF from the GI documentation.
The signature of this function is: toCdfDocument(data, jsxid)
. The first parameter (data
) is the array or object that you wish to be converted into a CDF document, the second is the jsxid attribute to be applied to the root node of the document.
For example, suppose you have some service that is exported by DWR:
public class SocialNetwork { public List<People> getFriends() ... // ... }
And you call this from JavaScript like this:
SocialNetwork.getFriends(function(friendList) { alert("You have " + friendList.length + " friends."); });
The friendList
variable is an array of objects that might look something like this:
friendList = [ { id:'1', address:'71 Yellow Drive', name:'Shiela MacDonald' }, { id:'2', address:'23 Red Close', name:'Joe Smith' }, ... ];
But what you really want to do is to display your friends in a GI matrix, or some other widget. To achieve this you would normally put a CDF document into your applications data cache. You can create a CDF document from an array of objects like this:
SocialNetwork.getFriends(function(friendList) { var cdf = dwr.gi.toCdfDocument(friendList, "jsxid"); giApp.getCache().setDocument("friendDataId", cdf); giApp.getJSXByName('friendMatrix').repaint(); });
The cdf
variable above is a CDF document that might contain records that look something like this:
<data jsxid='jsxid'> <record jsxid='1187' id='1' address='71 Yellow Drive' name='Shiela MacDonald'/> <record jsxid='1195' id='2' address='23 Red Close' name='Joe Smith'/> ... </data>
toCdfDocument()
will ensure that if objects passed to it have a jsxid property, this will be used as the jsxid for that record, or if none is available, one will be automatically generated.