| By Ryan Anklam | Article Rating: |
|
| March 19, 2006 09:15 AM EST | Reads: |
30,185 |
Now let's say that the connection to the database was down when the user first entered the application. The function in Listing 1 is used to get a list of all the departments in the company.
If the database server is down the cfcatch will catch a database error and throw a new error message that will tell the user that the database server is down, it's up to the page that calls this function to trap the error and set the session.error and session.errorMessage variables:
<cfscript>
try
{
Department = CreateObject("Component","CFDJ.Components.Department");
DepartmentArray = Department.GetAllDepartments(#session.dsn#);
}
catch(Any ex)
{
session.error = true;
session.errorMessage = ex.Message;
}
</cfscript>
In this case the employee update page would look like Figure 4 when the user enters the application.
Next let's look at using JavaScript to do some simple client-side error handling. The first step is to check for invalid data. I'll assume that you've had some experience doing simple JavaScript error checking and skip right to displaying the error. For our example, we're going to have the JavaScript check to make sure that the user has selected the name of a user to edit from the user drop-down. The first step would be to make sure that the selected index of a drop-down is not zero. Typically the next step would be to display some sort of message to the user with the Alert() function. In this case we'll simply call the ShowError() function that we wrote above:
if(departmentSelect.selectedIndex != 0)
{
//do something
}
else
{
ShowMessage('Please select an employee to update',true);
}
Conclusion
Adding a messaging system to an AJAX application isn't a very complicated, but it can be an extremely useful technique for keeping your end users informed. This application can be viewed online at www.innovacreative.com/cfdj/ajax. The source code can be downloaded from www.innovacreative.com/cfdj/ajax/ajax.zip.
Published March 19, 2006 Reads 30,185
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Ryan Anklam
Ryan Anklam is the Chief Information Officer at Innova Creative Media, Inc. His current focus is on using ColdFusion to develop large scale hosted applications. Ryan has been developing ColdFusion applications since 1996. In addition, he is also a Microsoft Certified Professional with demonstrated skills in C# and SQL Server.
![]() |
Kim 03/20/06 03:07:22 PM EST | |||
On page two, it reads Creating JavaScript to Handle the Errors I don't see where we created the query or the template to update the employee record so far in the article. |
||||
![]() |
Dave 03/20/06 12:34:38 PM EST | |||
Unfortunately the links to the demo and zip file are not working for this article. Is there another place one can test this out and download the source? Thanks, |
||||
![]() |
SYS-CON India News Desk 03/19/06 10:31:11 AM EST | |||
AJAX has become an increasingly popular tool to develop RIAs. With AJAX, as with many new technologies, developers often overlook core application issues such as error handling. While many current AJAX frameworks come with ways to handle errors, the built-in error-handling methods might not be quite what you need, and it's possible that you might not even want to adopt a specific AJAX framework at all. So how do you handle errors in AJAX? |
||||
![]() |
SYS-CON Italy News Desk 03/19/06 09:50:32 AM EST | |||
AJAX has become an increasingly popular tool to develop RIAs. With AJAX, as with many new technologies, developers often overlook core application issues such as error handling. While many current AJAX frameworks come with ways to handle errors, the built-in error-handling methods might not be quite what you need, and it's possible that you might not even want to adopt a specific AJAX framework at all. So how do you handle errors in AJAX? |
||||
![]() |
Dev 03/19/06 08:30:53 AM EST | |||
The URL for download the source cannot be reached. Is there any other way to get the source ? |
||||
![]() |
Dev 03/19/06 08:30:43 AM EST | |||
The URL for download the source cannot be reached. Is there any other way to get the source ? |
||||
- 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























