Welcome!

AJAX & REA Authors: John Funnell, Bob Little, Kevin Hoffman, Maureen O'Gara, Onkar Singh

Related Topics: AJAX & REA, ColdFusion, Adobe Flex

AJAX & REA: Article

Simplifying AJAX with the Spry Framework

Delivering great experiences while fitting the workflows and skill sets of both designers & developers

Assuming that we're using the XML sample from our previous example this code snippet creates the following HTML:

Master/Detail Data Sets
The Spry framework supports the concept of Master/Detail Data Sets. This implies that the selected record in a Master Data Set drives the contents of the Detail Data Set. There are many ways to create this relationship using Spry. In our example the Master Data Set and the Detail Data Set retrieves data from different sections of the same XML file. Each time a new record is selected in the Master Data Set, the Detail Data Set retrieves a subset of the data.

The Master Data Set is used to retrieve the products for the Products table. The Detail Data Set is used to retrieve the product features once a specific product is selected in the Product table.

Detail Data Set Declaration
The Detail Data Set and its relationship to the Master Data Set can be set up easily using one additional line of JavaScript:

Note that the main difference in the Detail Data Set declaration is the XPath. This XPath includes a filter expression and uses a Spry Token. The filter expression limits the nodes that will be returned for the dsProductFeatures Detail Data Set. The Spry token represents the "name" field for the current record in the dsProducts Master Data Set.

In effect the declaration states that the dsProductFeatures Detail Data Set will fetch its data based on the value of the "name" field in the current record of the dsProducts Master Data Set (see Figure 6). Every time the user selects a new record in the Master Data Set, this Detail Data Set will automatically update.

Master/Detail Regions
In Figure 7 the dsProductFeatures Detail Data Set is used to display the features of a selected product in the Accordion widget. When the user chooses a new product in the Product table, the features will change in the Accordion without needing a page refresh.

Spry Widgets
Spry widgets are UI elements that make it easier for your users to interact with the content on the page. The current set of widgets (so far) includes:

  • Accordion
  • Menu Bar
  • Collapsible Panel
  • Tabbed Panels
  • Text Field
  • Text Area
  • Checkbox & Checkbox Group
  • Select list
The Widget philosophy follows the Spry guiding principles:
  • Widgets must be easy to modify (re-style).
  • Code must be easy to understand.
  • HTML-centric markup.
  • No custom tags.
  • No programmatic injection of markup.
  • Self-contained (limit dependencies on additional libraries).
Anatomy of a Widget
Each widget is broken down into three modules as in Figure 8.

More Stories By Paul Gubbay

Paul Gubbay is a director of engineering at Macromedia. Previously, Paul held the role of CEO at CyberSage Software, where he spent several years building the vision and infrastructure of the company. Under Paul's guidance, CyberSage focused on emerging technologies such as XML, Java, and Macromedia Flash to deliver leading edge product offerings.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.