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
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
"There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, introduced two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a multip...
Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
SYS-CON Events announced today that Evatronix 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. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
An increasing number of companies are creating products that combine data with analytical capabilities. Running interactive queries on Big Data requires complex architectures to store and query data effectively, typically involving data streams, an choosing efficient file format/database and multiple independent systems that are tied together through custom-engineered pipelines. In his session at @BigDataExpo at @ThingsExpo, Tomer Levi, a senior software engineer at Intel’s Advanced Analytics gr...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things’). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing? IoT is not about the devices, it’s about the data consumed and generated. The devices are tools, mechanisms, conduits. In his session at Internet of Things at Cloud Expo | DXWor...
Everything run by electricity will eventually be connected to the Internet. Get ahead of the Internet of Things revolution. In his session at @ThingsExpo, Akvelon expert and IoT industry leader Sergey Grebnov provided an educational dive into the world of managing your home, workplace and all the devices they contain with the power of machine-based AI and intelligent Bot services for a completely streamlined experience.
SYS-CON Events announced today that Synametrics Technologies will exhibit at SYS-CON's 22nd International Cloud Expo®, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Synametrics Technologies is a privately held company based in Plainsboro, New Jersey that has been providing solutions for the developer community since 1997. Based on the success of its initial product offerings such as WinSQL, Xeams, SynaMan and Syncrify, Synametrics continues to create and hone inn...