YOUR FEEDBACK
Ross Cooney wrote: Buying servers is capital intensive...and impossible for startups. Buying capaci...


2008 East
DIAMOND SPONSOR:
Data Direct
Frontiers in Data Access: The Coming Wave in Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
Intel
Virtualization – Path to Predictive Enterprise
Green Hills
IT Security in a Hostile World
JBoss / freedom oss
Practical SOA Approach
GOLD SPONSORS:
Software AG
The Art & Science of SOA: How Governance Enables Adoption
PlateSpin
Effective Planning for Virtual Infrastructure Growth
Fujitsu
Automated Business Process Discovery & Virtualization Service
Ceedo
Workspace Virtualization
Click For 2007 West
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
MXDJ TOP LINKS YOU MUST CLICK ON !


The Real Estate Sample Application Using ColdFusion and Flash Forms
Create an application that allows users to retrieve records from a database

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 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 , 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();">

<cfformitem type="script">

   formOnLoad():Void{
     //declare global variable
RealEstateAdmin.myGlobalObjects = {};

//call set up
setUpRemoting();

     //set other properties as needed }      //rest of the code

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 a built-in , you're going to create it next.
Creating the submitSearch()
Within the same <cfformitem type="script"> tag, add the new :
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 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 follows:

//get all the search criteria items
var searchArguments = {};

//in order to get data contained in Text inputs,
//use myTextInputName.text searchArguments.mls_id = search_mls_id.text;

//to get data from radio buttons,
//use myRadioButtonName.selectedData
searchArguments.status = search_status.selectedData;

//checkboxes store their true/false value in their selected property,
//myCheckboxName.selected searchArguments.hasPool =
search_hasPool.selected; searchArguments.hasWalkInClosets =
search_hasWalkInClosets.selected; searchArguments.hasLaundry =
search_hasLaundry.selected; searchArguments.hasFireplace =
search_hasFireplace.selected;

//to get the selected choice in a dropdown,
//use mySelectName.value or mySelectName.selectedItem.data searchArguments.footage =
search_footage.value; searchArguments.bedrooms =
search_bedrooms.value; searchArguments.bathrooms =
search_bathrooms. value; searchArguments.priceFrom =
search_priceRangeFrom.value; searchArguments.priceTo =
search_priceRangeTo.value;

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 will see that the was empty, which doesn't help much - when the results are returned, they will just be ignored (see Figure 5).

Adding a Grid for the Results
The sample application shows the search results in a datagrid next to the Search panel. To implement this functionality, add a grid using cfgrid and name it listingGrid:

<cfgrid name="listingGrid" rowheaders="false">
    <cfgridcolumn name="price" header="Price" />
    <cfgridcolumn name="bedrooms" header="Bedrooms" />
    <cfgridcolumn name="bathrooms" header="Bathrooms" />
    <cfgridcolumn name="footage" header="Footage" />
    <cfgridcolumn name="type" header="Type" /> </cfgrid>

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;
responseHandler.onResult = (results: Object):Void {
     listingGrid.dataProvider = results; }
Because the CFC might throw an error,
you should also complete the onStatus to handle error responses:
responseHandler.onStatus = ( stat: Object ):Void {
     alert("Error: " + stat.description); }

Dealing with Asynchronous Processes
If the service returns a query, you might be wondering why you can't simply use the following code:

//wrong code
listingGrid.dataProvider = listingService.search(searchArgs);

The above code is not correct because the call to search is done asynchronously. As soon as the call is triggered, it does not wait for the server's response; it continues running code written below it. For this reason, you must create an object (called responseHanldler here) with functions that will be called when the server sends a response.

Another point to consider is that any communication across a network is unreliable. If the returned dataset is large, it might take some time to load. When using the page refresh model, the browser takes care of adding a progress bar to indicate that the next page is loading. Although this is not perfect, it does offer some feedback to the user. Now that your application does not use a page refresh model, how do you indicate to users that their request is being processed and they have to wait?

There are several approaches to this. A simple method is to show the default clock cursor that Flash Forms use when they load data. This is a simple solution that is consistent with the other functions of Flash Forms. To add that functionality, insert the following snippet before making the call to the remote service in index.cfm:

mx.managers.CursorManager.showBusyCursor();
When the results come back, remove the cursor:
mx.managers.CursorManager.removeBusyCursor();

Add this snippet to both the onResult and onStatus functions because you don't know which one will get called.

Part 2 to this article can be found at www.macromedia.com/devnet.

The sample files for this article can be downloaded at www.macromedia.com/devnet/coldfusion/articles/flashforms.html

About Nahuel Foronda
Nahuel Foronda is one of the founders of Blue Instant (http://www.blueinstant.com), a web development firm specializing in Rich Internet Applications where he has been creating award-winning applications and offering training for the last five years. He also maintains a blog, called AS Fusion (http://www.asfusion.com), where he writes about Flash, ColdFusion and other web technologies.

About Laura Arguello
Laura Arguello is one of the founders of Blue Instant (http://www.blueinstant.com), a web development firm specializing in Rich Internet Applications where she has been creating award-winning applications and offering training for the last five years. She also maintains a blog, called AS Fusion (http://www.asfusion.com), where she writes about Flash, ColdFusion and other web technologies.

YOUR FEEDBACK
SYS-CON India News Desk wrote: With the release of Macromedia ColdFusion 7 and the arrival of Flash Forms, developers were presented with an alternative to HTML forms that offered them additional functionality, such as full-featured controls not available in HTML and built-in validation. That alone made Flash Forms appealing - and with the addition of pieces of ActionScript code, developers were able to create truly responsive forms. But because they were meant to be compatible with HTML forms, they still shared the same submit-refresh model. What if you could 'submit' the form and, without a page refresh, get feedback from the server?
SYS-CON Italy News Desk wrote: With the release of Macromedia ColdFusion 7 and the arrival of Flash Forms, developers were presented with an alternative to HTML forms that offered them additional functionality, such as full-featured controls not available in HTML and built-in validation. That alone made Flash Forms appealing - and with the addition of pieces of ActionScript code, developers were able to create truly responsive forms. But because they were meant to be compatible with HTML forms, they still shared the same submit-refresh model. What if you could 'submit' the form and, without a page refresh, get feedback from the server?
LATEST FLEX STORIES & POSTS
I spoke on a panel at Mashup Camp this week on why Ajax Standards matter. I was quoted by Doug Henschen of Intelligent Enterprise as saying that we are locked in a struggle for the soul of the web, so I thought I would expand on that theme. Just because the web has been open so far doe...
Adobe and ARM are gonna put Flash Player 10 and AIR, the stuff of web video and rich Internet apps, on ARM widgets by the second half of next year. They mean phones, set-tops, MIDs, TVs, car mojo and personal media devices, which have so far only had access to Flash Lite, not the best ...
This is my final blog from the Adobe MAX 2008 conference.
New releases of Flex software were announced at MAX. How Flash Catalyst works.
Notes from the openning day of Adobe MAX 2008
Of all domestic air carriers, I like Continental the most. They showed Mamma Mia and the food was bearable. Last month, I was in the air for 14 hours flying to Japan, and now the trip across the USA is a piece of cake. I have only carry luggage with me. This small bag has all the cloth...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE