|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
TOP COLDFUSION LINKS CF & Flash ColdFusion "Real Estate Sample Application" (Part I)
Building the search functionality with Flash Forms
Jan. 27, 2006 01:45 PM
This object must implement the necessary functions that will be automatically called when the server sends a response from a CFC. The default functions called on this object are onResult and onStatus. The server calls onResult when the service sends a successful response and calls onStatus when the service throws an error or when some other type of error occurs. That means that the responseHandler object must have those two functions if it is expected to act upon service responses:
responseHandler.onResult = ( results: Object ):Void { Once the responseHandler objects knows how to behave, the actual service can be instantiated and stored in a global variable (RealEstateAdmin.myGlobalObjects), as follows:
RealEstateAdmin.myGlobalObjects.listingService = The getService() method of the connection class takes two parameters; the first is the path to the service. To get the path to your service, find the directory structure from your Web root to your CFC, replace the slashes with dots, and remove the CFC extension. For instance, if you saved the sample files in a folder called RealEstate in your Web root and saved ListingManager.cfc in a folder called services, the path would be /RealEstate/services/ListingManager.cfc from a browser. Translating that to dot notation becomes RealEstate.services.ListingManager. The second parameter is the object that handles the responses, which is the object you just created: responseHandler. Note that the service is not actually created until you call a method on the service. So if you enter an incorrect path, you will not know it until you try to call it. Now you have a method that sets up a Flash Remoting service, but if you never call this, the service will never be set up. You can use the onload attribute of the cfform tag, which was introduced with the ColdFusion 7.01 Updater to call the service, as follows: <cfform name="RealEstateAdmin" format="flash" onload=" setUpRemoting()"> That is not enough, however, because the service is stored in a global variable that you must also declare as the form loads. You can create yet another to be called as the form loads that sets up this global variable and possibly other settings. While you are at it, call the setUpRemoting() right after that, as follows:
<cfform name="RealEstateAdmin" format="flash" onload="formOnLoad();"> Assigning the Flash Remoting service to a global variable is only a suggestion. The most important code is what's inside the setUpRemoting(). Finally, you are ready to call the service. Your Search panel readily accepts user input. You have set up the Flash Remoting service and your CFC is eagerly waiting to be called. Remember how the Search panel had a Search button? Now you can make it functional by adding some actions to its onClick attribute: <cfinput type="button" name="searchSubmit" value="Search" onclick="submitSearch()" /> But wait a minute. What is the submitSearch()? Because it is not built-in, you're going to create it next.
Creating the submitSearch()
submitSearch():Void{ The purpose of the submitSearch() is to gather all the information entered in the Search panel and send it to the ListingManager service. If you recall, the CFC has several arguments. When making the call, you could send each argument, in order, as parameters to the call. But that becomes error-prone if the CFC has many arguments. An easy way to send several parameters is to use a structure with keys that have the same name as the arguments. To create a structure, you instantiate an empty object (or structure) that will be the container for all the data entered in the Search panel form fields. Then, one by one, take the data entered in each field and assign it to a key in the empty object, as shown in Listing 3. Once you have gathered all the necessary data for the structure, you can make the call to your CFC, sending all the parameters as one structure. Recall that "search' was the name of the service in the ListingManager CFC: RealEstateAdmin.myGlobalObjects.listingService.search(searchArgs); After you call the service and the matching records are retrieved, the server will send a query back with the results, even if it is an empty query. The responseHandler object handles the response in its onResult , but if you go back to the "Calling the Service" section, you'll see that the query was empty, which doesn't help much - when the results are returned, they will just be ignored.
Adding a Grid for the Results
<cfgrid name="listingGrid" rowheaders="false"> Notice that the headers of visible columns are properly named and the name attribute of each cfgridcolumn tag corresponds to a query column name. Now that you have a control, assign the results to the grid's data provider:
var listingGrid = listingGrid; YOUR FEEDBACK
CFDJ LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||