A couple days ago, I posted an example of how Adobe's Spry Framework allows one to easily and quickly incorporate XML datasets into an application, allowing for a great alternative to page-to-page navigation and data mining.

One of the limitations I pointed out was the initial amount of coding involved. Well, that was because I'm an idiot.

While I've used Spry's Spry.Data.XMLDataSet() many times before, I literally had no idea how powerful it is, nor that it could interact with dynamically generated XML files, such as I was doing with ColdFusion components in my last example. However, such is not the case. Not only does this method allow me to do everything I was doing before, it involves a heck of lot less code. The entire invoke for the datasets here is:

var dsCities = new Spry.Data.XMLDataSet("getlocations.cfc method=getCities", "cities/city");

var dsLocations = new Spry.Data.XMLDataSet("getlocations.cfc?method=getLocations&cityID={dsCities::@id}", "locations/location");

Two lines of javascript! Now of course, there is more to handle some of the behaviors…but I have effectively cut out about 100 lines from what I was doing before. Pretty cool!

Finally, the best part about this is it allows me to take full advantage of the framework's "spry:state". With this, one can set different "states" that will fire in relation to the loading of the datasets. So, while the data is loading, one can display a sexy progress gif using "spry:state=loading". And when the dataset is retrieved, one can use "spry:state=ready" to display the returned datasets.

Oh yeah, one LAST thing. Using datasets like this makes dynamic callbacks a breeze. Imagine I have items that a user can save to their "favorites". Using the "spry:if", I can tell the browser to display certain elements certain ways depending on the recordsets that are returned (i.e., whether or not the user has a particular item saved to their favorites). Before Spry, I would have the user "save" the favorite which would reload the page, re-hit the database, and alter the display to show the changes to the data. With Spry, however, the page reload is no longer necessary. Rather, one can simply tell the callback function from the insert query to recompile the Spry dataset asychronously. Because the data that's currently being display is based on this dataset, the returned information will be refreshed automatically, all without the need of a single page reload.

Blah, blah, blah. Enough of this. Here's a slightly more sexy example of what I've been talking about.