ColdFusion, WDDX, and NetObjects Fusion

by Tom Molyneux

Editor's Note: If you're the kind of Web developer that understands cryptic acronyms and needs all of the power they stand for, then you'll be interested in WDDX. If you aren't highly technical and don't need your Web site to work like a software program, reading this article may give you a headache :)

One of the latest buzzwords in the software industry is "rentalware." The concept is that users will be able to rent software over the Internet instead of forking out large one-time fees for software purchases and upgrades. This promises to do away with the cumbersome distribution of software on CDs and diskettes and the attendant headaches of supporting different operating systems and older versions. While this is a laudable goal, it is currently very difficult to get an application delivered over the 'Net to behave with anything near the speed of a locally installed or client-server application.

This is where Allaire's WDDX (Web Distributed Data eXchange) can help. Instead of hitting the server each time a new record is required, WDDX loads entire record sets onto the client's browser.

This has two enormous benefits. For the end user, once a record set has been loaded, it is, in essence, working locally, making the application much faster and more responsive.

From the developer's standpoint, server requests and database queries may be reduced by a magnitude of between 3 and 250 times. The best way to demonstrate the benefits of the WDDX approach over the standard, dumb-client approach, is with a case study. I will discuss an overall Web-based application and how we at Fundere used Allaire's ColdFusion , ColdFusion Studio, and NetObjects Fusion to build one part of this application.

Case study

ExamWeb distributes software on disk and by download. Its software provides test preparation for exams such as the California Real Estate Exam and the LSAT. One of the main features of the software is an exam simulator that allows students to build and take practice exams on their computers. The stand-alone software is full featured: It tracks time spent on each question and the student's score in each test area (i.e., reading comprehension). It allows the student to analyze many facets of past test performance as well as reload partially taken exams.

We were able to capture all of these features using ColdFusion. However, one very practical reason led us to use WDDX for this application: time. Imagine taking a 250-question exam where you had to hit the server each time you answered a question. Most users without a T1 line would walk away in frustration after the first couple of questions.

WDDX solved this problem. The student could make a single request to the server at the start of the exam and then work with the same record set during the next hour without making another server request. (You can see this demonstrated at http://209.249.196.112/examweb/demo/. You will need to create a demo account.)

Development

view in browser 

One part of the application was a glossary of real estate terms powered by WDDX. The application works as follows:

The page displays a form with letter buttons across the top from A to Z. When the student clicks on a letter, all words beginning with that letter are loaded into the words combo box below. When the user clicks on one of the words, its definition is displayed below in the definition text area. By loading all of the records at one time using WDDX, we reduce the number of server requests by at least 3 times (the student only gets one form vs. getting one form and submitting it two times.) If the student wants to look up more than one term, the savings is even greater. Best of all, it's fast.

NetObjects

To create the glossary, we used NetObjects Fusion to design the form. We created a form using the NetObjects Fusion table tool with a combo box named "words," a text area named "definition," and 26 buttons across the top labeled "A to Z."

page inside NetObjects Fusion 

We gave each button an event handler, using the HTML Inside Tag feature, coded as onClick="loadCurrentLetter('e');".

Load Current Letter 

We also created an event handler for the combo box, coded as onClick="loadCurrentDefinition();". In our work with NetObjects, we did not use the Allaire ColdFusion Connector. The Connector was designed for common ColdFusion tasks and this is a very custom application. Instead, we used a CFInclude statement to include a ColdFusion template we created in ColdFusion Studio.

ColdFusion Studio

Our included template contains the ColdFusion code that creates the WDDX record set and the two JavaScript functions called by our event handlers. We run a query to get all terms and definitions in our glossary table and create a WDDX record set using the CFWDDX tag.

If you wish to learn more about WDDX, Ben Forta does an excellent job discussing it in his book ColdFusion 4.0 Application Development.

Once we have created our record set, we write two JavaScript functions. The first, loadCurrentLetter('x'), loads all words beginning with the selected letter into the words combo box. The second, loadCurrentDefinition(), loads the definition for the selected letter into the text area.

ColdFusion Code

<!---Get all records in glossary table --->
<cfquery name="GetTerms" datasource="myDatasource" dbtype="ODBC">
SELECT Glossary.Word, Glossary.Definition
FROM Glossary
ORDER BY Glossary.Word
</cfquery>

<!--- Include Allaire's WDDX / Javascript support --->
<SCRIPT SRC="/cfide/scripts/wddx.js" LANGUAGE="JAVASCRIPT"></SCRIPT>
<SCRIPT Language="JAVASCRIPT" >
<!-- Hide from old browsers
<!--- Convert query to Javascript object named "terms" --->
<CFWDDX
ACTION="CFML2JS"
INPUT="#GetTerms#"
TOPLEVELVARIABLE="terms">

function loadCurrentLetter(letter) {
//clear old words
document.glossaryform.words.options.length = 0;
for (i = 0; i < terms.word.length;i++) {
// match first letter
if (terms.word[i].charAt(0).toLowerCase() == letter) {
//create option
NewOpt = new Option;
NewOpt.value = i;
NewOpt.text = terms.word[i];
// Add the new object to the SELECT list
document.glossaryform.words.options[document.glossa ryform.words.options.length] = NewOpt;
}
}

}
//function loads current definition into the definition text area
//need to include error checking if not selected
function loadCurrentDefinition() {
//deselect item if it is the loading placeholder
if (document.glossaryform.words.options[document.gloss aryform.words.selectedIndex].text.charAt(0) == "=") {
document.glossaryform.words.selectedIndex=-1;
return;
}
// otherwise load the current definition
else {
var selected = document.glossaryform.words.options[document.glossa ryform.words.selectedIndex].value;
document.glossaryform.definition.value='';
document.glossaryform.definition.value=terms.defini tion[selected];
return;
}
}
//-->
</SCRIPT>

Conclusion

As the Web evolves, more and more software will be distributed as rentalware. Allaire's WDDX can be a tremendous help in creating Web-based applications that behave like local or client-server applications.

About WDDX

WDDX is an XML-based technology that enables the exchange of complex data between Web programming languages, creating what some refer to as "Web syndicate networks." WDDX consists of a language-independent representation of data based on an XML 1.0 DTD, and a set of modules for a wide variety of languages that use WDDX. WDDX can be used with HTTP, SMTP, POP, FTP, and other Internet protocols that support transferring textual data. For more information on WDDX, visit http://www.wddx.org/.

About the author

Tom Molyneux Tom Molyneux is the director of Fundere Software. Fundere is a private corporation, Fundere specializes in ColdFusion-NetObjects Fusion integration. Fundere provides training, on-site installation, and support for clients using NetObjects Fusion with ColdFusion. Fundere also builds custom NetObjects components that integrate NetObjects with other Web technologies.

For more information about Fundere, please contact:
Fundere Software, 18 Horizon Ave., Venice, CA 90291 Phone: (310) 392-1005
Fax: (310) 392-0800
 

[Home] [Start Here] [Plan] [Design] [Build] [Grow] [FuseLetter] [New]

SITE MAP - Contact us - Legal Info
www.efuse.com ©2000, NetObjects

Sign up for our free FuseLetter!

BuiltByNOF

bullet Try NetObjects Fusion for free
bullet Buy  NetObjects Fusion 4 for $49
bulletBuy FusionMX for $99

Learn about NetObjects Training Classes

fuseman