ColdFusion provides support for mixing native ColdFusion elements and Spry elements in a single application.

  • ColdFusion tags use Spry data sets directly in bind expressions. Therefore, a ColdFusion form element, such as cfinput, binds to a field in a dynamic Spry data set, and is updated each time the data set updates, including when the user selects an item in a Spry control or dynamic region that the data set populates. To
    bind to a Spry data set, specify the data set name followed by the
    path to the specific element that you bind to, by using standard
    Spry path syntax. For example, if dsFilters is a Spry data set with
    a name column, the {} bind parameter
    binds to the value of the current row's name column. The bind parameter cannotspecify an event; the bind expression is re-evaluated each time the selected row in the data set changes. The following example shows the bind syntax:

    <cfinput name="Input1" type="text"


  • 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:



  • 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 namevalue changes.

    options="{method: 'POST'}"


ColdFusion includes the complete Spry 1.5 framework release in web_root/_CFIDE/scripts/ajax/spry directory. For more information about Spry framework, see 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
    For this example to display images, create an images subdirectory of your application directory that contains images with the names specified by the BOOKIMAGE column of the cfbookclub database BOOKS table.
The roundtrip.cfm page

<html xmlns="" xmlns:spry="">

<!--- The screen.css style sheet is provided in the Spry distribution. --->
<link href="screen.css" rel="stylesheet" type="text/css" media="all"/>
<!--- Include the XPath and Spry JavaScript files. --->
<script type="text/javascript"
<script type="text/javascript"

<!--- Create the dsFilters Spry XML data set used to populate the FiltersList dynamic region
that lists the filters. Call the GridDataManager CFC getFilter method directly from a
Spry XMLDataSet function because no binding is needed. --->
var dsFilters = new
Spry.Data.XMLDataSet("GridDataManager.cfc?method=getFilter", "filters/filter");

<!--- Use a cfsprydataset tag with binding to generate a dsProduct Spry data set with details
about the book grid selection. --->
options="{method: 'POST'}"

<!--- Function to handle bind errors. --->
<script language="javascript">
errorHandler = function(code,msg){
alert("Error w/bind occurred. See details below:\n\n" + "Error Code: "
+ code + "\n" + "Error Message: " + msg);

<!--- Specify the size of the FiltersList Spry dynamic region.
By default it would be unnecessarily large. --->
<style type="text/css">
#FiltersList {
width: 150px;

<!--- A Spry dynamic region containing repeated ListBoxItem controls.
Each item specifies a filter to use in filling the book list grid.
The items are populated by the data from the CFC getFilter method. --->
<div id="FiltersList" spry:region="dsFilters" class="SpryHiddenRegion">
<div spry:repeat="dsFilters" class="ListBoxItemGroup">
<div class="ListBoxItem"
spry:selectgroup="feedsList" spry:select="SelectedListBoxItem"

<!--- A ColdFusion form with the book list data grid. --->
<cfform name="bookform">
<!--- Create a book list grid.
Users select the book for which to get details from this grid.
Populate it with the results of the CFC getData method.
Pass the method the value of the name field of the selected
item in the dsfilters Spry dynamic region. --->
<cfgrid name="bookgrid"
<cfgridcolumn name="TITLE" header="Name" width=200>
<cfgridcolumn name="GENRE" header="Type" width=200>
</cfgrid><br />
<!--- Show the value of the name field of the selected item in the Spry dynamic region.
<cfinput name="filter" bind="{}">


<!--- A Spry dynamic region that uses the dsProduct data set to display information on the
selected product. --->
<div id="RSSResultsList" spry:detailregion="dsProduct" class="SpryHiddenRegion">
<img src="images/{bookimage}" alt="product box shot" width="238" height="130"/>



The gridDataManager.cfc file

<cfcomponent name="GridDataManager">

<!--- The getFilter function gets the filter XML to populate the dsFilters Spry data set.
It specifies returnFormat=plain to send XML text. --->
<cffunction name="getFilter" access="remote" output="false" returnFormat="plain">
<cffile action="read" file="#ExpandPath('.')#\Filters.xml" variable="filtersxml">
<cfcontent type="text/xml" reset="yes">
<cfreturn filtersxml>

<!--- The getData function returns books that match the specified genre, or all books if
there is no genre. --->
<cffunction name="getData" access="remote" output="false">
<cfargument name="page" required="yes">
<cfargument name="pageSize" required="yes">
<cfargument name="sortCol" required="yes">
<cfargument name="sortDir" required="yes">
<cfargument name="filter" required="no">
<cfquery name="books" datasource="cfbookclub">
select TITLE, GENRE from BOOKS
<cfif isDefined("arguments.filter") AND arguments.filter NEQ "">
where GENRE = '#arguments.filter#'
<cfif arguments.sortCol NEQ "" AND arguments.sortDir NEQ "">
order by #arguments.sortCol# #arguments.sortDir#
order by TITLE ASC
<!--- Return the data only for the current page. --->
<cfreturn QueryConvertForGrid(books,,

<!--- The getProductDetails gets data for a single book and converts it to XML for use
in the dsProduct Spry data set. --->
<cffunction name="getProductDetails" access="remote" output="false">
<cfargument name="prodname" default="The Road">
<!--- Get the information about the book from the database. --->
<cfquery name="bookDetails" datasource="cfbookclub">
where TITLE = '#arguments.prodname#'
<!--- Convert the query results to XML. --->
<cfxml variable="BookDetailsXML" >
<?xml version="1.0" encoding="iso-8859-1"?>
<!--- Convert the XML object to an XML string. --->
<cfset xmldata = xmlparse(BookDetailsXML)>
<cfcontent type="text/xml" reset="yes">
<cfreturn xmldata>


The Filters.xml file
<?xml version="1.0" encoding="iso-8859-1"?>

<description>No Filter</description>

<description>Look for Fiction</description>

<description>Look for Nonfiction</description>


This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy