
875
DEVELOPING
COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Las
t
upda
te
d 8/5/2010
•
Spry data sets use a CFC function as the data source. To do this, you simply specify the URL of the CFC in the
Spry.Data.XMLDataSet function, just as you would invoke any remote CFC method using a URL. Specify the
method name with a method URL parameter, and pass data to the function in additional URL parameters, as in the
following example:
Spry.Data.XMLDataSet("MyAppMgr.cfc?method=getFilter&filter=scores",
"filters/filter");
•
The cfsprydataset tag dynamically creates and updates Spry XML or JSON data sets based on ColdFusion form data.
Spry dynamic regions and other elements then use this data to control their display.
The following example shows a
cfsprydataset
tag that creates a Spry XML data set named dsProducts by calling
the getData.getProductDetails function and passing it the value of the selected name in a
cfgrid
control. The data
set updates each time the
name
value changes.
<cfsprydataset
name="dsProducts"
type="xml"
bind="CFC:getData.getProductDetails(prodname={myform:mygrid.name})"
xpath="products/product"
options="{method: 'POST'}"
onBindError="errorHandler">
ColdFusion includes the complete Spry 1.5 framework release in
web_root/
CFIDE/scripts/ajax/spry directory. For
more information about Spry framework, see
www.adobe.com/go/learn_spry_framework_en
. For more information,
see the cfsprydataset tag in the
CFML Reference
.
Spry data set example
This example has the following behavior:
1
It uses a CFC function directly to populate a Spry XML data set, from an XML file.
2
It displays information from the Spry data in a Spry dynamic region list box.
3
It uses the selected item in the Spry data set to control the contents of a
cfgrid
control. The
cfgrid
bind expression
calls a CFC and passes it a parameter bound to the selected item in the Spry XML data set.
4
It creates a second Spry XML data set by using a
cfsprydataset
tag that binds to the selected item in the
cfgrid
control and calls a CFC function.
5
It displays information from the second Spry data set in a second Spry dynamic region.
The example lets a user select the genre of books to display: all books, fiction, or nonfiction from a Spry list box
populated from the XML file. The selected genre determines the information displayed by a
cfgrid
control, and a text
input control shows the selected genre. The selected item in the
cfgrid
control determines the information that is
displayed in a second Spry dynamic region.
The application consists of the following files:
•
A roundtrip.cfm page with the display controls and related logic
•
A GridDataManager.cfc file with two functions:
•
A getFilter function that gets the XML for the spry data set
•
A getData function that gets the contents of the cfgrid control
•
A getProduct function that gets detailed information on the selected book
•
A Filters.xml file with the XML data for the spry data set