Sakai gadgets, sdata, and DWR
I spent today at the Sakai hackathon hosted by CARET. In addition to enjoying the sights and avoiding the pouring rain in Cambridge, I spent some time looking at the new gadgets+sdata techniques that the cambridge folks are using to build their dynamic (and flat!) portal. It’s great to see that the ajax “revolution” has made its way into sakai. Here are my notes on sdata, and how DWR may be an appropriate substitute for this tool in certain situations.
Sakai’s sdata tool is a webapp that can be configured to dispatch URLs to specific handlers. The documentation, as far as I can tell, is here. The web.xml file contains the configuration that maps URLs and query parameters (methods) to the Java handlers.
My first gadget experiment involved calling /sdata/mcp (which stands for my course and project sites, I believe) to begin implementing part of the UX improvement mockups. The call to /sdata/mcp returns a list of sites for which I’m currently a member, including interesting tidbits like the number of members in the site. It’s clear that this could be a useful and reusable “Javascript Service” for a number of UI gadgets.
However, once I started working on this particular UI, I realized that I needed data from a tagging service, and this isn’t provided via /sdata/mcp (or any other /sdata URLs at this time). I could imagine getting a set of requirements that required merging gradebook data with, say forum posts, along with site memberships, for some kind of forum grading overview widget. Who knows what those UI designers will come up with
The problem this poses is that there will be a constant push on the sdata tool to either incorporate new URL handlers as gadget designers and implementors think of new and exciting gadgets, or there will be a proliferation of ajax calls from clients trying to join data from a variety of services.
In these cases, I propose that we forego the use of sdata entirely, and utilize the DWR library instead. DWR provides some compelling advantages over sdata, along with some added costs. Here’s how I think DWR stacks up against sdata for sakai gadget development
Pros
- Data can be shaped on the server side however the client wants it shaped, so a single XHR can provide everything the gadget needs to render itself.
- Gadget developers can do all of their development in their gadget without need for modifying sdata, and dealing with the merge headaches that will inevitably come from a centralized service.
- DWR is a popular library for exposing java classes as ajax services, so the pool of developers with DWR expertise will likely be larger than those with sdata expertise.
Cons
- Each gadget (or collection of gadgets sharing a webapp) wishing to use DWR requires a dwr.xml configuration file. My gadget’s dwr.xml file is 9 lines, so I don’t think this is too onerous.
- Gadgets wishing to reuse an existing ajax service either need to copy the service into their own dwr-enabled webapp, or they need to assume that the other webapp will be deployed at runtime. For this reason, it may make sense to centralize often-used ajax services in sdata. It’s all a matter of tradeoffs between reuse and flexibility.
- Performance. DWR generates Javascript files on the fly via a servlet. This will presumably add more load to an application server than serving up a static .js file, but my guess is that this will be minimal. DWR 3, along with JAWR, provides a mechanism for serving cached and compressed .js files.
I’ve uploaded a zip file containing a preliminary sites gadget. It is nowhere near feature-complete, but it demonstrates both the sdata method (via /devwidgets/sites/sites.html) and the dwr method (…/sites_dwr.html). Please have a look and let me know (via email, IM, or via sakai-dev) what you think.