|
|
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
Digg This!
Page 2 of 4
« previous page
next page »
Coding the Search Query The search in this component has several arguments that correspond to the different search criteria: status, price, pool and other amenities, and so forth. It contains a simple query using the cfquery tag. All the arguments have a default value and the SQL statements will vary each time a user specifies a different combination of arguments. For instance, if the user doesn't enter a status, the CFC ignores that criteria; therefore, the SQL statement will not contain that column in its WHERE clause. To exclude it, we used a simple cfif tag (see Listing 1). When the query finishes processing, the CFC returns the results to the caller through the <cfreturn listingQuery /> tag. So far, you should be familiar with the methods used. You created a form to request data from the user and wrapped a query in a CFC to retrieve data from a database. You may be wondering how to connect the form and the CFC. Read onward.
Creating the Flash Remoting Service Just as Web services do, you must place Flash Remoting services in a Web-accessible directory. To create such a service, you use a CFC, writing the functions that you want to provide to the service consumers. These functions must have their access attribute set to remote in order to be accessible to Flash consumers. Here is a simple example of a service:
<cfcomponent> We could have included the code that queries the database in the service CFC but it is better to separate presentation from data layers and keep well-defined tasks encapsulated in different components. In this way, the core components that access the database can be completely separate from service components that may access them. The service components, knowing that they are services, can offer additional functionality specifically targeted to Flash, such as formatting. There is another advantage to this approach. It is common practice to keep components instantiated in a scope that spans several requests, such as the application or session scopes. When a Flash Remoting call is made to a component, however, this component is instantiated at that time - and every time a request is made, a new instance of the component is created. This means that Flash Remoting cannot call an already instantiated component residing in memory in a shared scope. The only way to resolve this issue is to have a service component that differs from the component that does the actual work. When Flash Remoting calls the service component, this can reference the component residing in memory and make the appropriate invocations. For simplicity's sake, this example instantiates ListingGateway.cfc but the source files use the memory-resident CFC approach (see Figure 4). Because the Search panel sends simple data types that match the types expected by the ListingGateway component, the service can simply pass the same arguments along by using an argumentCollection (see Listing 2). Name this component ListingService.cfc and save it in the services folders.
Calling the Service Please note that this address might be different if you are using the built-in Web server option (if your Web root is located at http://localhost:8500).
Adding ActionScript to the Flash Form Because you will use this Flash Remoting service several times, we recommend that you store it in a variable that can be used by other functions and controls. Wrap the Flash Remoting setup code that creates the service and stores this variable in a called setUpRemoting():
<cfformitem type="script"> Inside the cfformitem tag, declare the connection and service proxy as local variables:
//note the gateway address Declare an object that handles all the responses: var responseHandler:Object = {}; Page 2 of 4 « previous page next page »
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 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||