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
"When we talk about cloud without compromise what we're talking about is that when people think about 'I need the flexibility of the cloud' - it's the ability to create applications and run them in a cloud environment that's far more flexible,” explained Matthew Finnie, CTO of Interoute, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
The Internet giants are fully embracing AI. All the services they offer to their customers are aimed at drawing a map of the world with the data they get. The AIs from these companies are used to build disruptive approaches that cannot be used by established enterprises, which are threatened by these disruptions. However, most leaders underestimate the effect this will have on their businesses. In his session at 21st Cloud Expo, Rene Buest, Director Market Research & Technology Evangelism at Ara...
No hype cycles or predictions of zillions of things here. IoT is big. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, Associate Partner at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He discussed the evaluation of communication standards and IoT messaging protocols, data analytics considerations, edge-to-cloud tec...
New competitors, disruptive technologies, and growing expectations are pushing every business to both adopt and deliver new digital services. This ‘Digital Transformation’ demands rapid delivery and continuous iteration of new competitive services via multiple channels, which in turn demands new service delivery techniques – including DevOps. In this power panel at @DevOpsSummit 20th Cloud Expo, moderated by DevOps Conference Co-Chair Andi Mann, panelists examined how DevOps helps to meet the de...
When growing capacity and power in the data center, the architectural trade-offs between server scale-up vs. scale-out continue to be debated. Both approaches are valid: scale-out adds multiple, smaller servers running in a distributed computing model, while scale-up adds fewer, more powerful servers that are capable of running larger workloads. It’s worth noting that there are additional, unique advantages that scale-up architectures offer. One big advantage is large memory and compute capacity...
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.
Amazon started as an online bookseller 20 years ago. Since then, it has evolved into a technology juggernaut that has disrupted multiple markets and industries and touches many aspects of our lives. It is a relentless technology and business model innovator driving disruption throughout numerous ecosystems. Amazon’s AWS revenues alone are approaching $16B a year making it one of the largest IT companies in the world. With dominant offerings in Cloud, IoT, eCommerce, Big Data, AI, Digital Assista...
Artificial intelligence, machine learning, neural networks. We’re in the midst of a wave of excitement around AI such as hasn’t been seen for a few decades. But those previous periods of inflated expectations led to troughs of disappointment. Will this time be different? Most likely. Applications of AI such as predictive analytics are already decreasing costs and improving reliability of industrial machinery. Furthermore, the funding and research going into AI now comes from a wide range of com...
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...
We build IoT infrastructure products - when you have to integrate different devices, different systems and cloud you have to build an application to do that but we eliminate the need to build an application. Our products can integrate any device, any system, any cloud regardless of protocol," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA
SYS-CON Events announced today that Ayehu will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara California. Ayehu provides IT Process Automation & Orchestration solutions for IT and Security professionals to identify and resolve critical incidents and enable rapid containment, eradication, and recovery from cyber security breaches. Ayehu provides customers greater control over IT infras...
SYS-CON Events announced today that MobiDev, a client-oriented software development company, 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. MobiDev is a software company that develops and delivers turn-key mobile apps, websites, web services, and complex software systems for startups and enterprises. Since 2009 it has grown from a small group of passionate engineers and business...
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...
SYS-CON Events announced today that Enzu will exhibit at SYS-CON's 21st Int\ernational Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Enzu’s mission is to be the leading provider of enterprise cloud solutions worldwide. Enzu enables online businesses to use its IT infrastructure to their competitive advantage. By offering a suite of proven hosting and management services, Enzu wants companies to focus on the core of their ...
SYS-CON Events announced today that Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud com...
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.
In his session at Cloud Expo, Alan Winters, an entertainment executive/TV producer turned serial entrepreneur, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to ma...
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...
Multiple data types are pouring into IoT deployments. Data is coming in small packages as well as enormous files and data streams of many sizes. Widespread use of mobile devices adds to the total. In this power panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists looked at the tools and environments that are being put to use in IoT deployments, as well as the team skills a modern enterprise IT shop needs to keep things running, get a handle on all this data, and deliver...
In his session at @ThingsExpo, Eric Lachapelle, CEO of the Professional Evaluation and Certification Board (PECB), provided an overview of various initiatives to certify the security of connected devices and future trends in ensuring public trust of IoT. Eric Lachapelle is the Chief Executive Officer of the Professional Evaluation and Certification Board (PECB), an international certification body. His role is to help companies and individuals to achieve professional, accredited and worldwide re...