I know I've been posting alot about Spry lately, but the more I use it, the more I love it!  Using the simple-to-implement tools which Spry provides, I am able to spend more time dealing with server-side processing, rather than fighting javascript to get a couple of cool effects.  

A few weeks ago, I blogged about using Spry to return confirmation or error messages for a registration form asychronously to alert users to possible errors in their form BEFORE submission.

Today's example is based on the same principle, although more of an "independant app."  A week ago, a co-worker and I were talking about the idea of placing a "feed reader" inside of a web page, so that users could not only display links to feeds that they follow, but also allow for the feed to be displayed directly in the page.  After our conversation, my thoughts immediately turned to Spry as I was sure a quick, easy solution would be possible.

I was right.

There is really nothing to this.  In classic Spry usability-friendliness, this can be accomplished in about two lines of code:

 

var dsFeeds = new Spry.Data.XMLDataSet("getfeeds.cfc?method=updateFeed", "feeds/feed", { useCache:false });
var dsFeedContent = new Spry.Data.XMLDataSet("getfeeds.cfc?method=getFeeds&feedURL={dsFeeds::link}", "rss/channel/item");

The first line creates a Spry dataset–dsFeeds–which is populated from an invocation of the method "updateFeed" which is remotely exposed from my component.  

The second line's method, "getFeeds", takes one argument, the url passed from the first dataset, and returns a nice xml string for Spry to play with.

Now the second part of this threw me for a bit of a loop.  Originally, I was only passing the url to the method–but nothing was happening.  ColdFusion would return the xml data, but it was not exposed for Spry to use.  I banged my head for several minutes, double-checking code here and there, unable to find the problem.  Then I remembered what the problem was.

AJAX calls are localized; they cannot be made across servers.  So while I was passing the right argument to my method, the information that was returned was non-local, and was therefore not exposable to Spry.  Luckily, ColdFusion created an easy solution.  I simply passed the original URL argument to <cfhttp>
and saved the result to a variable.  I then dealt with this (now local) variable in the normal way, returned it to Spry, and voila! it worked.  I will not forget that again!

Anyway, that's about enough for that.  I have souped this up a little bit, just to show the flexibility which Spry provides.  In this example, the application starts with zero Feed Entries, and the user is required to populate a list.  When the appropriate addFeed() function is fired, a session structure is created to hold the values, as well as any others that are created in the future.  Obviously, the same could be easily refitted for a database, hard-coded XML files, etc., but I like this one because it really shows off how interesting Spry can make a website.

As a disclaimer, while I have enhanced a bit of the functionality, there is much that is glaringly missing.  I have no validation for proper URL's, no regex's for wierd URL characters, etc., so it should not be incredible difficult to break immediately if one is so inclined.  Also, there is a bit of a quirk with the way the session structure sorts the entries.  So yeah, there are issues.  However, I think those interested in Spry will see the promise that even such a ridiculously simple example engenders.

See the example here .