Comments
litl_phil wrote: While it's nice that Google and Acer share the vision of cloud-based computing, it's also worth noting that we at litl already have a webbook on the market (available at litl.com) that runs our own cloud-based OS. Unlike Chrome, litlOS is focused on creating a new and better web experience for the home, so we don't have the usual browser interface, we have our own innovative UI. In conjunction with easel mode (litl's inverted-V position) and our growing cohort of litl channels (special apps t...
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


AJAX Custom Error Handling: Enhancing the Interactive User Experience
AJAX and Rich Internet Applications

If everything in the update goes okay the ColdFusion template will send the page a success XML message that would look something like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<data>
<Success>Successfully updated employee record.</Success>
</data>

Now, let's say that the extension is in use. Our ColdFusion template will return a error XML message that would look something like:

<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
<data>
<error>There was a error updating the employee, extension is in use by Desmond Mason.
Please call the help desk at x555.
</error>
</data>

To complete the application we have to have a way to handle the XML sent back to the requesting page.

Creating JavaScript to Handle the Errors
Let's take a look at what we've done so far: we've created our CSS style classes, we've created our display container, we have our query, our template to update the employee record, and created our error-handling logic. The next step is to read the response from the server, parse through the XML, and set the appropriate display condition. We'll start this step by creating a function to show error messages. This function will need two parameters: the message text and an indication of whether or not this is an error message.

We'll start writing this function by setting a variable with a value that will represent the name of the message area - this, again, is our display container. Now that we have our display container we have to set the class of the display container conditionally based on the error parameter. Finally, we can set the innerHTML property of message node equal to the message's value:

function ShowMessage(message, isError)
{
    messageArea = document.getElementsByName('message')[0];

    if(isError)
    {
      messageArea.className = 'error';
    }
    else
    {
      messageArea.className = 'message';
    }

    messageArea.style.display = 'block';
    messageArea.innerHTML = message;
}
if(response.childNodes[0].nodeName == 'error')
{
ShowMessage(response.childNodes[0].firstChild.nodeValue,true);
}

After the ShowMessage function is written we have to write the logic to check the value of the first node returned. Since we called an update page we expect the first node to be named either "error" or "success" so we create code that will check to see if this is true:

if(response.childNodes[0].nodeName == 'error')
{
ShowMessage(response.childNodes[0].firstChild.nodeValue,true);
}
else
{
ShowMessage(response.childNodes[0].firstChild.nodeValue,false);
}

Let's look at our example of updating the employee record again. In the first case we got an XML message that looked like:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<data>
<Success>Successfully updated employee record.</Success>
</data>

In this case our script would call the ShowMessage function with the error Boolean value set to false. The resulting page would look something like Figure 2.

Now let's look at the same page if the server returned an error because the employee's extension is used by another employee. As mentioned above, the XML message returned from the ColdFusion template would look like:

<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
<data>
<error>There was a error updating the employee, extension is in use by Desmond Mason.
Please call the help desk at x555.</error>
</data>

In this case our script would call the ShowMessage function with the error Boolean value set to true. The resulting page would look something like Figure 3.

Coupling with Client-Side and Template Error Checking
To make the messaging system complete we have to integrate traditional ColdFusion error checking as well as client-side error checking.

Let's look at how to integrate traditional ColdFusion error handling into our messaging system first. We'll start by creating two session variables: one to hold a Boolean value to determine if an error has occurred and a second one that will be a string to hold the error message that we're going to return to the visitor. For this example I'll name them session.error and session.errorMessage. The next step is to wrap all your ColdFusion logic in the <cftry> and <cfcatch> statements. In your <cfcatch> statement you'll set the session.error to true and the session.errorMessage equal to the cfcatch.Message.

try
{
Department = CreateObject("Component","CFDJ.Components.Department");
DepartmentArray = Department.GetAllDepartments(#session.dsn#);
}
catch(Any ex)
{
      session.error = true;
      session.errorMessage = ex.Message;
}

Finally we'll have to add some logic to control the visibility of our message area. If the session.error message is false the display area is created exactly as before. However, if an error is found we'll set the default style of the message area to "error" and display the error message:

<cfif NOT session.error>
     <span id="message" name="message" class="hidden"></span>
<cfelse>
<span id="message" name="message" class="error">#session.errorMessage#</span>
     <cfset session.error = false>
</cfif>

About 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.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

On page two, it reads Creating JavaScript to Handle the Errors
Let's take a look at what we've done so far: we've created our CSS style classes, we've created our display container, we have our query, our template to update the employee record, and created our error-handling logic.

I don't see where we created the query or the template to update the employee record so far in the article.

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,
Dave

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?

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?

The URL for download the source cannot be reached. Is there any other way to get the source ?

The URL for download the source cannot be reached. Is there any other way to get the source ?


Your Feedback
Kim wrote: On page two, it reads Creating JavaScript to Handle the Errors Let's take a look at what we've done so far: we've created our CSS style classes, we've created our display container, we have our query, our template to update the employee record, and created our error-handling logic. I don't see where we created the query or the template to update the employee record so far in the article.
Dave wrote: 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, Dave
SYS-CON India News Desk wrote: 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 wrote: 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 wrote: The URL for download the source cannot be reached. Is there any other way to get the source ?
Dev wrote: The URL for download the source cannot be reached. Is there any other way to get the source ?
Enterprise Open Source Magazine Latest Stories . . .
Oracle seems to have divided the open source ranks over the MySQL delay it’s having closing its acquisition of Sun. Eben Moglin, the GPL’s most ardent defender and delineator, the lawyer who has worked hand in glove for years with the Free Software Foundation’s founder Richard Stallman...
Cloud computing is a game changer. The cloud is disrupting traditional software and hardware business models by disrupting how IT service gets delivered. Entrepreneurial opportunities abound as this classic disruptive technology begins to proliferate, so it is no surprise that SYS-CON'...
The irony is that Oracle has advanced MySQL, lost money in the process, and helped its competitors - all at the same time. When Oracle buys Sun and controls MySQL the gift (other than to Microsoft SQL Server) keeps on giving as the existential threat to RDBs is managed by Redwood Shore...
WSO2, the open source SOA company, today announced the launch of the WSO2 Cloud Platform. Available today, the new WSO2 Cloud Platform features a family of WSO2 Cloud Virtual Machines; WSO2 Cloud Connectors for enabling fast, secure cloud services; and the multi-tenant WSO2 Governance-...
Now, the open source Mozilla Thunderbird client software can be used with Open-Xchange collaboration software. The "Community OXtender for Thunderbird" software connector gives users full access to appointments and contacts stored in the Open-Xchange Server and enables them to use Thun...
Morph Labs, a leading provider of enterprise cloud computing technology, today announced an introductory trial of the Morph CloudServer, an open, standards-based server IT organizations can use to rapidly model and evaluate their cloud implementations. A miniature "Cloud Environment in...
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