aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Ajax Patterns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Ajax Patterns" Watch "Ajax Patterns" New topic
Author

Ajax Patterns

Liyaquat Ali
Ranch Hand

Joined: Nov 16, 2005
Posts: 156
The book (Ajax Patterns and Best Practices) by Christian Gross is a welcome sign as it deals with patterns, patterns to be used for Ajax based applications, and not just the procedure calls and technicalities of the Ajax API.

Assuming that we have a web app developed using ajax technology then does that mean that we have just load page in browser(User Interface) and make all requests to the server using ajax. If yes then that would mean that when we need to show another page(options) we will need to hide old elements and display new ones. Because we would make a call to the server, maybe to search for books, and when we get the results, we display the results and hide the search options, and when the user selects a book, make another ajax request to get the book details and then hide the search results and display the book info. This can be done using layers, but if we use something like this for a larger application then wouldn't the User Interface for the web application be just one big file(JSP or otherwise) and wouldn't it get very very complicated?

How would you suggest we tackle such a scenario, or rather how should Ajax be used?


Excuse me while I kiss the sky (Jimi Hendrix)
Christian Gross
Author
Ranch Hand

Joined: Feb 20, 2006
Posts: 85
You are right on all points.

The question is does this result in one big file (JSP, etc) that contains everything?

To avoid the problem of creating a huge honking HTML page you need to think of Content Chunking and granularization. Still complexity can arise and it asks the question how to manage the complexity. The answer lies in creating Content Chunks using JavaScript.

Here is how I would do it. Following is the URL to load the main content.

http://mydomain.com/main

The main page needs a menu and downloads the menu at the URL

http://mydomain.com/main/menu

Where things are different is that the downloaded content is not HTML, but JavaScript. The downloaded JavaScript is a self-contained chunk that contains the logic of how to create the menu. The main resource contains an incomplete type when called will execute the appropriate logic. Following is the source code that is executed to illustrate an incomplete type. The variable async.onComplete is the asynchronous XMLHttpRequest callback.

asynch.onComplete = function( status, statuscode, text, xml) {
evals( text);
menu.create(); // Incomplete type
}

The variable menu is an incomplete type because when the original main resource is downloaded there is no definition for menu. To make menu complete the /main/menu chunk is downloaded, and executed. Contained within the menu.create() is the logic to create the menu.

Using incomplete types is identical to Java components in that menu.create is the interface, and the resource /main/menu is the implementation. Using this approach allows you to modularize an Ajax application and distribute logic among individual resources. For example, when the call /main/menu is made the server could implement need to know security as the server has the ability to choose the implementation at runtime.

Does this help?

Christian


Author of Ajax Patterns and Best Practices
Liyaquat Ali
Ranch Hand

Joined: Nov 16, 2005
Posts: 156
Hi Christian,

Firstly, thanx for answering the question, it definitely helps. While waiting for a reply I went through the other threads(It must be Fate etc.) and read Ur suggestions there, it all makes sense now.

So it seems javascript is all the more important in an Ajax based application, and logic distributed in different chunks so design has to be so good it should work like a clock!

I understand that in your book you have explained patterns using code examples and scenarios, I would like to know if there is javascript code as well in the pattern implementation examples in your book?

Thanx again,

Best of Luck with Ur book!

Ali
[ February 21, 2006: Message edited by: Liyaquat Ali ]
Christian Gross
Author
Ranch Hand

Joined: Feb 20, 2006
Posts: 85
Yes, exactly JavaScript and its layout, structure, etc is all the more important with an Ajax application. It will make or break your application.

The pattern implementations have enough JavaScript to make the patterns work. There is a small library of common functions (XMLHttpRequest instantiation, Asynchronous Callbacks, etc) that is available from the subversion database

http://www.devspace.com/repos/ajaxpatterns

(Edited the URL to remove period as per next comment...)
Look under the directory /website/lib.

Christian
[ February 21, 2006: Message edited by: Christian Gross ]
Liyaquat Ali
Ranch Hand

Joined: Nov 16, 2005
Posts: 156
Thanx again Christian,

U'v been a gr8 help. I cant wait to get my hands on that book!

Ali

P.S: the link U sent needs sum editing(The dot @ the end)
http://www.devspace.com/repos/ajaxpatterns
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ajax Patterns