Welcome!

You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: ColdFusion, Adobe Flex, Machine Learning

ColdFusion: Article

An Introduction to AJAX and Taconite

Yes, it works

AJAX stands for Asynchronous JavaScript and XML. The core of AJAX is the use of the XMLHttpRequest() object to communicate with server-side scripts. It can send and receive information in XML, HTML, and plain text.

The "Asynchronous" part means the client can communicate with the server without page refreshes. This allows you to update portions of a page based upon user events and is what allows developers to create Rich Internet Applications (RIA) using existing technologies.

Introducing Taconite
Taconite is a framework that simplifies the creation of AJAX-enabled Web applications. It's a very lightweight framework that automates the tedious tasks related to AJAX development, such as the creation and management of the XMLHttpRequest object and the creation of dynamic content. Taconite can be used with all modern Web browsers (Firefox, Safari, IE, Opera, and Konqueror, to name a few) and can be used with any server-side technology, including Java EE, .NET, PHP, ColdFusion or any language that lets you return XHTML.

The XMLHttpRequest object is not officially part of any Web standard, including W3C standards. Hence, the W3C created the Document Object Model Load and Save specification. Taconite is based on the concepts behind the W3C's Document Object Model Load and Save specification.

The heart of Taconite is a parser that converts normal (X)HTML code into a series of JavaScript commands that dynamically create the content on the browser. This parser allows the developer to write content in a way that is natural - as (X)HTML. You no longer have to crowd your pages with a slew of document.createElement and document.appendChild commands to dynamically create new content. The resulting JavaScript is evaluated by the browser's JavaScript engine to produce the content specified by the (X)HTML. All you need to do is make sure that the content being generated is valid XHTML. That means single tags must be self-closing, attributes need to be in quotes, special characters need to be escaped and attribute minimization must be avoided (i.e., nowrap should be nowrap="nowrap").

The Taconite custom parser is implemented as a set of JSP custom tags that can be used in any Java servlet container, or as a client-side JavaScript library, meaning it can be used in conjunction with virtually any server-side technology.

Taconite focuses on removing the tedious task of writing large amounts of JavaScript to dynamically update content on a Web page. Unlike some frameworks that try to invent a new way of sending request data to the server, Taconite relies on the tried-and-true name/value pairs either embedded within the query string of a GET request, or tucked safely into the body of a POST. The client-side library even automates the creation of the name/value query string. All you need to worry about is telling Taconite what values should be sent to the server, and it takes care of the rest.

Since the JavaScript is created by the parser based on the HTML you specify, you don't have to worry about dealing with browser JavaScript incompatibilities. The parser takes care of them all for you. All you need to do is specify the dynamic content as HTML, and the parser does the rest.

InnerHTML Avoided
Many of the currently available AJAX frameworks rely on the innerHTML property to dynamically create and update content on the Web page. Taconite completely avoids the use of innerHTML.

The main problem with innerHTML is that it's non-standard. It is not specified by any W3C recommendation, although it is supported by most of today's browsers. Another problem with innerHTML is that it really only applies to HTML documents, not XHTML documents, which is what the industry is moving to. As browsers move to better, more strict support for XHTML documents, they may not support innerHTML due to its non-standard nature.

Coming as a surprise to absolutely nobody, the innerHTML property has its own browser-to-browser quirks. For example, IE won't allow the innerHTML of a <table> to be appended. So, if you want to append one row to a table using innerHTML, you'll have to reproduce the entire contents of the table tag, with the one new row added at the end. That's just a waste of processing time and bandwidth.

Using the innerHTML property doesn't lend much control when it comes to placing the new content. For instance, if you want to insert a table row between two existing table rows using the innerHTML property, you would have to reproduce the entire table. Taconite gives you the flexibility to specify where content should be placed. In fact, this concept is straight out of the W3C DOM Load and Save specification.

Figure 1 shows the client HTML page. Note that there is only one link on the page (line 18). Clicking the link sends an AJAX request to the server, and the server's response is appended to the page.

Lines 7 and 8 reference Taconite JavaScript files. The taconite-client.js file is always required when Taconite is used. This file defines the AjaxRequest object, which is the heart of the Taconite client-side library. The taconite-parser.js file references the JavaScript-based Taconite parser. It is only required when you wish to perform the XHMTL-to-DOM parsing on the browser rather than on the server.

Lines 11-14 define the doHelloWorld function. Thanks to the Taconite framework, it's only two lines long. The first line creates an instance of the AjaxRequest object. The AjaxRequest object, as described by its name, encapsulates an AJAX request. Each instance of an AjaxRequest object creates its own instance of the XMLHttpRequest object, so you can create as many as you like without worrying about instances of XMLHttpRequest overwriting one another.

Line 18 defines the link that initiates the AJAX request when clicked. The link calls the doHelloWorld function, passing to it the URL of the AJAX service to be called.

The AjaxRequest object is created by passing a single argument to the object constructor. The argument is the URL to which the AJAX request will be sent.

The second line of the doHelloWorld function sends the request to the server. The AjaxRequest object defines a sendRequest method, which is called here to send the request. The rest is defined on the server, which we'll look at next.

Line 1 in Figure 2 is a directive indicating that the Content-Type of the page should be returned as text/xml. All Taconite responses must be returned with a Content-Type of text/xml, otherwise, the XMLHttpRequest object won't be able to parse it as an XML document. This file can be reproduced by any server-side technology; just set Content-Type to be text/xml.

Line 3 has the taconite-root XML tag, which is the root tag of all Taconite responses. All Taconite responses must have the taconite-root tag as the root tag. The presence of this tag ensures that the response is well-formed XML. Note that the taconite-root tag has an attribute of xml:space="preserve." This is to ensure that Internet Explorer handles whitespace correctly.

Line 5 opens the taconite-append-as-children tag. This tag says that the child elements of this tag will be appended as children to the context node. The context node is specified by the contextNodeID attribute. The value of this attribute must correspond to some element on the XHTML page. Remember the empty div element on Line 23 of the XHTML page, which had an ID attribute value of helloWorldContainer? This is where the message will be appended, because the contextNodeID attribute of the taconite-append-as-children tag has a value of helloWorldContainer.

The second attribute on the taconite-append-as-children tag is parseInBrowser, which has a value of true (when not using the JSP tags, parseInBrowser must always be true). This tells the AjaxRequest object that it needs to parse the response into JavaScript before running the JavaScript to produce the "Hello World" message.

Finally, the "Hello World!" message is defined on Lines 7-9. Notice how the message is simply defined as valid XHTML. In fact, the div tag even has an embedded style that makes the message font orange in color! This is the beauty of Taconite: you simply specify the new or updated content as regular ol' XHTML, and Taconite does the rest, without resorting to using the pesky innerHTML property.

Using Taconite with ColdFusion
AJAX really improves your user's experience. Your Web page appears to load faster because your application is responding to your user and only loading the necessary content. Entire page reloads are no longer necessary. How you approach designing your page changes. You become focused on how to respond to your user's actions. Your code becomes more precise and more manageable.

From the Team Behind AJAXWorld!
AJAXWorld Magazine is the pre-eminent independent vendor-neutral resource for the fastest growing new segment of the software business: entirely Web-based applications and experiences like Gmail, Google Maps, Live.com, MySpaces, and Flickr.

AJAXWorld Magazine recognizes that the next-generation user-centric Web is hurtling toward us and that it's a rich-media future in which AJAX, as the most talked about of all the Rich Internet technologies, is positioned firmly at center stage.

The first international AJAXWorld Conference & Expo which took place on October 2 - 4, 2006, at the Santa Clara Convention Center in Santa Clara, CA is sponsored by Adobe, Amazon, Apress, Backbase, ComponentArt, Cynergy Systems, Google, Helmi Technologies, IBM, ICEsoft, ILOG, Infragistics, JackBe, Laszlo Systems, Nexaweb, OASIS, Parasoft, Sun Microsystems, telerik, TIBCO, U7 Web Technologies, Visible Measures, Zapatec; including media sponsors AJAX Matters, AJAXWorld Magazine, BZ Media, ColdFusion Developer's Journal, DevtownStation.com, Eclipse Developer's Journal, Eclipse Review, Enterprise Open Source Magazine, Integration Developer News, ITtoolbox.com, Java Developer's Journal, LinuxWorld.com, Methods & Tools, Network World, Open Enterprise Trends, Sarbanes-Oxley Compliance Journal, SD Times, Software Test & Performance, SOA Web Services Journal, SYS-CON.TV, Web 2.0 Journal, and Web Developer's & Designer's Journal.

To date, more than 50 organizations have joined the OpenAjax Alliance, including:

Adobe
Ajaxian
American Greetings (AG/Interactive)
Backbase
BEA
Bling Software
Borland
Curl
Dojo Foundation
Eclipse Foundation
edge IPK
eLink Business Innovations
ENOVIA MatrixOne
Fair Isaac
Finetooth
The Front Side
Google
IBM
ICEsoft
Ikivo
ILOG
IN2
Innoopract
Intel
IT MILL
JackBe
Javeline
JWAX
Laszlo Systems
Merced Systems
Mozilla Corporation
Nexaweb
Nitobi
Novell
OpenLink Software
Openwave Systems
Opera
Oracle
Red Hat
SAP
Scalix
Seagull Software
Sitepen
Software AG
Sun Microsystems
Tibco
Vertex Logic
Vircom
Webtide
XML11
Zend Zimbra
Zoho

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.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
SYS-CON Events announced today that Dasher Technologies will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Dasher Technologies, Inc. ® is a premier IT solution provider that delivers expert technical resources along with trusted account executives to architect and deliver complete IT solutions and services to help our clients execute their goals, plans and objectives. Since 1999, we'v...
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp emp...
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
SYS-CON Events announced today that TidalScale, a leading provider of systems and services, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. TidalScale has been involved in shaping the computing landscape. They've designed, developed and deployed some of the most important and successful systems and services in the history of the computing industry - internet, Ethernet, operating s...
Infoblox delivers Actionable Network Intelligence to enterprise, government, and service provider customers around the world. They are the industry leader in DNS, DHCP, and IP address management, the category known as DDI. We empower thousands of organizations to control and secure their networks from the core-enabling them to increase efficiency and visibility, improve customer service, and meet compliance requirements.
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
Join IBM November 1 at 21st Cloud Expo at the Santa Clara Convention Center in Santa Clara, CA, and learn how IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Cognitive analysis impacts today’s systems with unparalleled ability that were previously available only to manned, back-end operations. Thanks to cloud processing, IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Imagine a robot vacuum that becomes your personal assistant tha...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, will lead you through the exciting evolution of the cloud. He'll look at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering ...
In a recent survey, Sumo Logic surveyed 1,500 customers who employ cloud services such as Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP). According to the survey, a quarter of the respondents have already deployed Docker containers and nearly as many (23 percent) are employing the AWS Lambda serverless computing framework. It’s clear: serverless is here to stay. The adoption does come with some needed changes, within both application development and operations. Tha...
SYS-CON Events announced today that Avere Systems, a leading provider of enterprise storage for the hybrid cloud, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Avere delivers a more modern architectural approach to storage that doesn't require the overprovisioning of storage capacity to achieve performance, overspending on expensive storage media for inactive data or the overbui...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
SYS-CON Events announced today that TidalScale will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. TidalScale is the leading provider of Software-Defined Servers that bring flexibility to modern data centers by right-sizing servers on the fly to fit any data set or workload. TidalScale’s award-winning inverse hypervisor technology combines multiple commodity servers (including their ass...
SYS-CON Events announced today that N3N will exhibit at SYS-CON's @ThingsExpo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. N3N’s solutions increase the effectiveness of operations and control centers, increase the value of IoT investments, and facilitate real-time operational decision making. N3N enables operations teams with a four dimensional digital “big board” that consolidates real-time live video feeds alongside IoT sensor data a...
As hybrid cloud becomes the de-facto standard mode of operation for most enterprises, new challenges arise on how to efficiently and economically share data across environments. In his session at 21st Cloud Expo, Dr. Allon Cohen, VP of Product at Elastifile, will explore new techniques and best practices that help enterprise IT benefit from the advantages of hybrid cloud environments by enabling data availability for both legacy enterprise and cloud-native mission critical applications. By rev...
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend 21st Cloud Expo October 31 - November 2, 2017, at the Santa Clara Convention Center, CA, and June 12-14, 2018, at the Javits Center in New York City, NY, and learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
Join IBM November 1 at 21st Cloud Expo at the Santa Clara Convention Center in Santa Clara, CA, and learn how IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Cognitive analysis impacts today’s systems with unparalleled ability that were previously available only to manned, back-end operations. Thanks to cloud processing, IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Imagine a robot vacuum that becomes your personal assistant th...
Digital transformation is changing the face of business. The IDC predicts that enterprises will commit to a massive new scale of digital transformation, to stake out leadership positions in the "digital transformation economy." Accordingly, attendees at the upcoming Cloud Expo | @ThingsExpo at the Santa Clara Convention Center in Santa Clara, CA, Oct 31-Nov 2, will find fresh new content in a new track called Enterprise Cloud & Digital Transformation.
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
Most technology leaders, contemporary and from the hardware era, are reshaping their businesses to do software. They hope to capture value from emerging technologies such as IoT, SDN, and AI. Ultimately, irrespective of the vertical, it is about deriving value from independent software applications participating in an ecosystem as one comprehensive solution. In his session at @ThingsExpo, Kausik Sridhar, founder and CTO of Pulzze Systems, will discuss how given the magnitude of today's applicati...
What is the best strategy for selecting the right offshore company for your business? In his session at 21st Cloud Expo, Alan Winters, U.S. Head of Business Development at MobiDev, will discuss the things to look for - positive and negative - in evaluating your options. He will also discuss how to maximize productivity with your offshore developers. Before you start your search, clearly understand your business needs and how that impacts software choices.