| By Tom Schreck, Jason Doyle | Article Rating: |
|
| January 25, 2007 01:45 PM EST | Reads: |
20,654 |
Incorporating Taconite and AJAX into your ColdFusion development is seamless. Typically, you do the following:
- Determine the point in your app where your user will kick off an AJAX request. Typically, this is a link or a button that, when clicked, calls a JavaScript function that starts the AJAX request process. This step may pass data to the JavaScript function that will be sent to the server for processing.
- Determine what area(s) on the page will be modified/updated on the client. An AJAX response can change the content in several locations on the client.
- Determine what server-side file should be called to process the AJAX request.
- Determine what business logic needs to happen inside the server-side file using the parameters passed from the AJAX request.
- Construct the response(s) you want to send back to the client page.
Below are examples of how I incorporated the steps above inside cfcPowerTools (www.cfcpowertools.com). cfcPowerTools is a Web-based application used to batch generate ColdFusion Components (CFCs) from database tables.
1. Determine the point in your app where your user will kick off an AJAX request. The end user creates a project used to organize CFCs. The UI has a drop down for selecting a project. AJAX is used to load all of the Packages within a project and to clear out the main content area. The Project dropdown passes the projectID to the JavaScript function that initiates a Taconite call.
//GetPackages
01 function GetPackages(projectID)
02{
03 var url = "getPackages.cfm";
04 var packageRequest = new AjaxRequest(url);
05 packageRequest.setQueryString('projectID=' + projectID);
06 //packageRequest.setEchoDebugInfo();
07 packageRequest.sendRequest();
08}
The GetPackages JavaScript function accepts the projectID that will be appended to the URL. The URL is defined in line 3. The AJAX request is created in line 4. The projectID is appended to the query string in line 5. You can turn debug on/off using line 6. Line 7 sends the request.
2. Determine which area(s) on the page will be modified/updated on the client. By selecting a Project, the Packages tab is updated and the main content area (white part) is cleared out. Below are the containers on the client awaiting content to be AJAX'd. Notice the ID values of each <div>:
<div id="zonePackages" class="leftNavDivs"></div>
<div id="zoneContent"></div>
3. Determine which server-side file should be called to process an AJAX request.
The GetPackages JavaScript function calls getPackages.cfm server file
(line 3). This file is responsible for processing any business logic
and assembling an AJAX response.
4. Determine which business logic needs to happen inside the server-side file using the parameters passed from the AJAX request. Refer to Figure 3. Line 5 is the business logic. It simply sets a session variable using the passed projectID.
5. Construct the response(s) you want to send back to the client page. Lines 8-12 construct the AJAX response. Line 8 replaces zonePackages with the contents of packageList.cfm. Line 12 clears out zoneContent.
Notice that the response is created within <cfsavecontent> tag (line 6). This allows you to better control the content being returned. The content is stored in variables.Content variable. Also, notice everything happens inside <cftry> block (line 4). This allows you to create an error message to be AJAX'd back to the client. Notice that inside <cfcatch> (line 14) another <cfsavecontent> (line 15) produces an error response (also named variables.Content). It returns content to an error div (<div id="zoneError"/>).
Regardless of whether an error happens, or the page successfully renders, content is returned to the client. Line 31 injects variables.Content into the Taconite response.
Notice the use of <cfcontent type="text/xml"> (line 26).
AJAX Tips
Here are some tips you may want to consider in your development:
1. Custom debug functionality. I found debugging Taconite to be a bit cumbersome. I've added a Taconite response to each page:
<!--- SHOW DEBUG --->
<cfif request.ynDebug>
<taconite-replace-children contextNodeID="zoneDebug" parseInBrowser="true">
<cfmodule template="debug.cfm">
</taconite-replace-children>
</cfif>
I have a <div id="zoneDebug"/> on the client page. It sits there waiting to receive debug information. If debugging is turned on, then I include a custom debug page whose contents are returned to the debug div.
2. AJAX requires the use of JavaScript. So, you will need to be sure your users allow JavaScript functionality in their browsers.
Conclusion
There are many layers to AJAX, but
using just the basic functionality can greatly improve the richness of
your application. Incorporating AJAX using the Taconite library is very
easy. Following the steps and examples above you can inject AJAX
functionality into your applications.
References
http://taconite.sourceforge.net/
Published January 25, 2007 Reads 20,654
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Tom Schreck
Tom Schreck is a Macromedia certified ColdFusion MX 6.1 developer. He has been working with ColdFusion since 1997. Check out www.cfcPowerTools.com for more information on cfcPowerTools.
More Stories By Jason Doyle
Jason Doyle is a Web systems engineer at Thomson. He is currently focusing on Rich Internet Applications with the use of mash-ups in a service-oriented environment.
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Adobe Cans Another 9% of its Workforce
- Moyea DVD4Web Converter V2.0 Converts DVD to FLV Fast and Synchronously with Watermarks
- Adobe Fiddles with its Web Apps
- Adobe & Salesforce Cut Cloud Deal
- Hosting.com Launches ColdFusion 9 in the Cloud
- The Real Time Infrastructure Ultimatum
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- The Planet Named “Bronze Sponsor” of Cloud Computing Expo
- Microsoft Expression Web Has Got Game
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Bruce Chizen Joins Voyager Capital as Venture Partner
- My Top Seven Wishes From Adobe MAX 2009
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- Constructing an Application with Flash Forms from the Ground Up
- AJAX World RIA Conference & Expo Kicks Off in New York City
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Personal Branding Checklist
- Adobe Flex 2: Advanced DataGrid
- Has the Technology Bounceback Begun?
- Building a Zip Code Proximity Search with ColdFusion
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- The Asynchronous CFML Gateway
- Web Services Using ColdFusion and Apache CXF


























