A getHandler is the page that delivers properly formatted XML data to the combobox. The combobox call the getHandler repeatedly as the user types to retrieve the correct list of records.
The combobox sends special querystring parameters to the getHandler. A typical request might look like:
These parameters help you build your SQL select statement. for a complete explanation of these parameters, see the article titled "Constructing SQL Queries for Combo V3"
This simple walkthrough will show you how to connect a basic grid to a datasource. In this case the datasource is an Access MDB file, although we have provided template SQL for a variety of databases in the SQL Queries tutorial.
The GetHandler
First we set up our Coldfusion page by defining the language we"ll be working in. We also need to include the Nitobi XML API (nitobi.xml.cfm) which is included.
The following code snippets will connect to a database and output 4 columns of xml data. You can output as many columns as you like and you need only use the ones you want in the ComboBox. See the bottom of this page for the corresponding Combo Tag.
Next we retrieve the querystring parameters that will let us write a SQL query. We need to collect information on the PageSize (number of records to return), SearchSubString (the text to search for) and LastString (the string at the bottom of the current list - useful for databases that do not support proper paging like MS Access).
Now we set up the EBAGetHandler API and data structures with a single call to EBAGetHandler_ProcessRecords
Now we define four data columns for the combo.
Now, assuming we've already set up our datasource in ColdFusion administrator, we can do our query. The following SQL query will work for the basic search modes like Filter, Classic, and Compact. The SmartSearch, and SmartList modes need double wildcard searching ("LIKE '%SearchSubString%'")
We can now loop through our records
Finally, we output the XML stream to the client.
Here is the entire code sample:
The Combo Tag
Now on the HTML side, here is an example of a combo tag that would bind to this data.
Notice in this tag the the first column (Customer Name) has DataFieldIndex = 0 meaning it will bind to the first data column (CustomerName). The second column we defined here (Customer eMail) is bound to DataFieldIndex = 2, meaning the 3rd column of data (CustomerEmail).
Comments:
Knowledgebase
To be notified of new articles when they're available, subscribe to our RSS feed.