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
With 10 simultaneous tracks, keynotes, general sessions and targeted breakout classes, Cloud Expo and @ThingsExpo are two of the most important technology events of the year. Since its launch over eight years ago, Cloud Expo and @ThingsExpo have presented a rock star faculty as well as showcased hundreds of sponsors and exhibitors! In this blog post, I provide 7 tips on how, as part of our world-class faculty, you can deliver one of the most popular sessions at our events. But before reading the...
SYS-CON Events announced today that CA Technologies has been named "Platinum Sponsor" of SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CA Technologies helps customers succeed in a future where every business - from apparel to energy - is being rewritten by software. From planning to development to management to security, CA creates software that fuels transformation for companies in the applic...
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...
SYS-CON Events announced today that GrapeUp, the leading provider of rapid product development at the speed of business, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Grape Up is a software company, specialized in cloud native application development and professional services related to Cloud Foundry PaaS. With five expert teams that operate in various sectors of the market acr...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
From 2013, NTT Communications has been providing cPaaS service, SkyWay. Its customer’s expectations for leveraging WebRTC technology are not only typical real-time communication use cases such as Web conference, remote education, but also IoT use cases such as remote camera monitoring, smart-glass, and robotic. Because of this, NTT Communications has numerous IoT business use-cases that its customers are developing on top of PaaS. WebRTC will lead IoT businesses to be more innovative and address...
In his opening keynote at 20th Cloud Expo, Michael Maximilien, Research Scientist, Architect, and Engineer at IBM, discussed the full potential of the cloud and social data requires artificial intelligence. By mixing Cloud Foundry and the rich set of Watson services, IBM's Bluemix is the best cloud operating system for enterprises today, providing rapid development and deployment of applications that can take advantage of the rich catalog of Watson services to help drive insights from the vast t...
SYS-CON Events announced today that Elastifile 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. Elastifile Cloud File System (ECFS) is software-defined data infrastructure designed for seamless and efficient management of dynamic workloads across heterogeneous environments. Elastifile provides the architecture needed to optimize your hybrid cloud environment, by facilitating efficient...
Recently, IoT seems emerging as a solution vehicle for data analytics on real-world scenarios from setting a room temperature setting to predicting a component failure of an aircraft. Compared with developing an application or deploying a cloud service, is an IoT solution unique? If so, how? How does a typical IoT solution architecture consist? And what are the essential components and how are they relevant to each other? How does the security play out? What are the best practices in formulating...
In his session at @ThingsExpo, Arvind Radhakrishnen discussed how IoT offers new business models in banking and financial services organizations with the capability to revolutionize products, payments, channels, business processes and asset management built on strong architectural foundation. The following topics were covered: How IoT stands to impact various business parameters including customer experience, cost and risk management within BFS organizations.
SYS-CON Events announced today that Golden Gate University 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. Since 1901, non-profit Golden Gate University (GGU) has been helping adults achieve their professional goals by providing high quality, practice-based undergraduate and graduate educational programs in law, taxation, business and related professions. Many of its courses are taug...
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, will introduce 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...
When shopping for a new data processing platform for IoT solutions, many development teams want to be able to test-drive options before making a choice. Yet when evaluating an IoT solution, it’s simply not feasible to do so at scale with physical devices. Building a sensor simulator is the next best choice; however, generating a realistic simulation at very high TPS with ease of configurability is a formidable challenge. When dealing with multiple application or transport protocols, you would be...
SYS-CON Events announced today that DXWorldExpo has been named “Global 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. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
21st International Cloud Expo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy. Me...
SYS-CON Events announced today that Secure Channels, a cybersecurity firm, 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. Secure Channels, Inc. offers several products and solutions to its many clients, helping them protect critical data from being compromised and access to computer networks from the unauthorized. The company develops comprehensive data encryption security strategie...
In his session at @ThingsExpo, Sudarshan Krishnamurthi, a Senior Manager, Business Strategy, at Cisco Systems, discussed how IT and operational technology (OT) work together, as opposed to being in separate siloes as once was traditional. Attendees learned how to fully leverage the power of IoT in their organization by bringing the two sides together and bridging the communication gap. He also looked at what good leadership must entail in order to accomplish this, and how IT managers can be the ...
Recently, WebRTC has a lot of eyes from market. The use cases of WebRTC are expanding - video chat, online education, online health care etc. Not only for human-to-human communication, but also IoT use cases such as machine to human use cases can be seen recently. One of the typical use-case is remote camera monitoring. With WebRTC, people can have interoperability and flexibility for deploying monitoring service. However, the benefit of WebRTC for IoT is not only its convenience and interopera...
There is only one world-class Cloud event on earth, and that is Cloud Expo – which returns to Silicon Valley for the 21st Cloud Expo at the Santa Clara Convention Center, October 31 - November 2, 2017. Every Global 2000 enterprise in the world is now integrating cloud computing in some form into its IT development and operations. Midsize and small businesses are also migrating to the cloud in increasing numbers. Companies are each developing their unique mix of cloud technologies and service...
When shopping for a new data processing platform for IoT solutions, many development teams want to be able to test-drive options before making a choice. Yet when evaluating an IoT solution, it’s simply not feasible to do so at scale with physical devices. Building a sensor simulator is the next best choice; however, generating a realistic simulation at very high TPS with ease of configurability is a formidable challenge. When dealing with multiple application or transport protocols, you would be...