http://java.sun.com/ http://java.sun.com/ http://www.sun.com/javaone
JavaOne - Experiencing Java technology through education, industry, and community
2006 Conference
Topics
Sessions
   General Sessions
Hands-on Labs
Schedule
Schedule Builder
Register
Pavilion
   Cosponsors
   Exhibitors
   Media
   Presentation Theater
Java University
Daily Activities
Event Connect
Alumni
   Alumni FAQ
Multimedia Sessions
Community
JavaOne Online
Forums
java.sun.com
java.net
java.com
sun.com/developers
Java Wear & Books
Home

An Introduction to (Ajax)

by John O'Conner

Ben Galbraith and Dion Almaer, founders of Ajaxian.com, spoke to an enthusiastic crowd on Tuesday afternoon during their session "An Introduction to (Ajax)" (TS-4489). Using simple but effective examples, the two made a compelling argument for using Asynchronous JavaScript with XML (AJAX) to create dynamic, responsive applications that are easy to deploy and that require nothing more than a common web browser.

(Ajax) represents a new way to process data in web pages, making it possible to update portions of a page rather than the entire page. Microsoft introduced parts of the technology in Internet Explorer as early as 1997, and Mozilla reproduced the functionality later in 2002. Most updated and current browsers support AJAX.

Of course, JavaScript technology is at the heart of (Ajax). JavaScript is a scripting language that developers used in the past to create interesting mouse roll-over behaviors, to animate buttons or backgrounds, and to perform minimal error checking of HTML form data before sending the form to the server. Those abilities are simple, even trivial, compared to what Ajax can do.

Providing much more than visual manipulation of page components, (Ajax) allows interactive requests and responses between a browser and a server, updating only those portions of a page that require it.

At the heart of (Ajax) is an object called XMLHttpRequest. An XMLHttpRequest object allows you to send and receive HTTP data asynchronously as you interact with a common HTML document. As you point, click, drag, drop, or enter data on web page components, Ajax allows JavaScript technology objects in the page to interact with a server. Because your page can send and receive data asynchronously, your interactions with the page are not suspended as the page communicates with a back-end server. The result is a responsive, changing web page that behaves much like a rich desktop client application.

(Ajax) applications can get several kinds of data back from a server:

  • XML data. Your JavaScript code can request additional data to fill in form contents and so on.

  • HTML data. As a result of your request, your (Ajax) code can change the type or appearance of graphical components on a page.

  • JavaScript code. Finally, your (Ajax) code can retrieve additional JavaScript technology instructions from a server.

Galbraith and Almaer tried to dispel several (Ajax) myths during their presentation:

Myth number 1: (Ajax) is hard.

The HTML file that the presenters used in their demonstration contained two text fields: a city and state field and a zip code field. After reading a zip code that the user typed into the first field, Galbraith and Almaer's (Ajax) code constructed an XmlHttpRequest, sent the request in the background, retrieved city and state information for that zip code, and filled in the second field. Although a somewhat trivial demo, it clearly showed that Ajax code is not hard to understand or difficult to write.

Myth number 2: Cross-browser differences are difficult to manage.

Unfortunately, different browsers implement the functionality of XMLHttpRequest differently. The call to create this object is different, for example, between the Microsoft Internet Explorer and the Mozilla Firefox browsers. If this were the only difference, I would say that you should not even consider cross-browser differences as you decide whether to adopt (Ajax). However, you can handle other differences by using popular and available Ajax libraries.

Myth number 3: If you want rich effects and widgets, desktop applications are a better choice than (Ajax).

Technologies such as JavaServer Faces provide rich, usable graphical components that you can manipulate and combine with (Ajax) code to provide interactive, visual experiences similar to those available from desktop applications.

Myth number 4: Off-line modes of operation are impossible.

They are definitely not impossible. The availability of embeddable Java technology databases such as Apache Derby allow developers to cache pages and data necessary for many off-line uses.

Myth number 5: Client-side validation is a pain.

There are so many libraries available that many common validation scenarios have well-tested, accessible solutions. Moreover, (Ajax) provides the ability to validate data across the network with little or no delays in the user experience. For example, a popular library called Direct Web Remoting (DWR) can assist with cross-network data validation.

What can (Ajax) do for your browser-based application?

(Ajax) can increase participation. Because users don't have to wait for page reloads or jump to other pages every time they interact with your site, they are more likely to answer questions and rate products, for example.

It can improve portals and forums. Specific portals areas on a page can update themselves without entire-page refreshes. Content stays fresh.

It provides rich client-side validation.

As you experiment with (Ajax), remember that you don't have to write all your own code. The many existing Ajax frameworks can simplify your project code and save you time. Some of the most popular libraries and frameworks are the following:

Given the excitement around and capabilities of (Ajax), should you abandon the Java technology, rich-client desktop? Absolutely not. Both Ajax and desktop technologies have their advantages and disadvantages. You might consider the following points when deciding where AJAX fits into your development plans:

(Ajax) Benefits Desktop Java Technology Benefits
Easy development model Greater speed than JavaScript technology
Easy deployment Advanced graphics
Mash ups Tight integration with the operating system
Clean separation of user interface (UI) and business logic Mature UI toolkit
Ultimate hackability Security or lack of hackability

Lots of (Ajax) sessions are available at this year's JavaOne conference. Remember to register and check for session changes using the JavaOne ScheduleBuilder. The following sessions, labs, and Birds-of-a-Feather (BOF) sessions may interest you:

(Ajax): Riding the Web Application Horse a Little Further (LAB-4255)
Thursday, May 18, 2006, 9:45-11:15 a.m.

Java Technology, (Ajax), Web 2.0 and SOA (TS-4372)
Thursday, May 18, 2006, 11:00 a.m.-12:00 p.m.

Using the Dojo Toolkit to Develop (Ajax)-Enabled Java EE Web Applications (TS-3577)
Thursday, May 18, 2:45-3:45 p.m.

Smackdown for (Ajax) Programming Models and Frameworks (TS-2991)
Thursday, May 18, 4:00-5:00 p.m.

Java BluePrints Application: Creating (Ajax)-Enabled Web 2.0 Java Pet Store Demo Software (BOF-2594)
Thursday, May 18, 2006, 7:30-8:20 p.m.

Evolving JavaServer Faces Technology: (Ajax) Done Right (TS-116)
Friday, May 19, 12:00-1:00 p.m.

Introduction to (Ajax) (TS-4489)
Friday, May 19, 2:30-3:30 p.m.

(Ajax) and Persistence: Emerging Patterns and Pain Points (TS-8614)
Friday, May 19, 2:30-3:30 p.m.

Introduction to (Ajax) (TS-4489)
Friday, May 19, 2:30-3:30 p.m.

JavaServer Faces, (Ajax), and Portlets: Developing Apps Without Distress (TS-6877)
Friday, May 19, 3:45-4:45 p.m.

More information about JavaScript technology and (Ajax) are available from the following sites:

Ajaxian
http://www.ajaxian.com/

(Ajax) Developer Resource Center
http://developers.sun.com/ajax/

JavaScript Technology
http://java.sun.com/javascript/

 Back to top


Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
If you would like a reply to your comment, please submit your email address:
Note: We may not respond to all submitted comments.