Ajax is everywhere with AjaxAnywhere

It’s been quite some time since I’ve started playing with AjaxAnywhere which I think one of the most interesting Ajax Frameworks out there drawing attention. Nowadays I’ve paired with Kenan Sevindik and began to explore the possibility of using AjaxAnywhere in our project. The idea behind is quite interesting actually, you specify zones in your page and these zones in dom are reloaded using javascript library of ajaxanywhere. The best thing is you do not need to change your current structure, just specify zones, add the zones to be refreshed and tada: the zones are reloaded with no postback.

The framework uses it’s own filter to manipulate the flow and currently it both supports jsp and jsf. The main idea is the following; The form is submitted as a whole actually not just the zones,  the JSF components(zones) output spans with the components’ ids, when the response reaches, the inner html of the span is set by the mechanisms in aa.js of ajaxanywhere.

The Good
I’ve managed to apply some cool ajax features in few minutes using the framework. For example, I’ve created two dependent comboboxes, and a datatable presenting the search results with no postback. I think these are nice examples that AjaxAnywhere can do to satisfy the impatient client. AA is very useful in these cases and considering the workload to create the same thing with phaselisteners, xml parsing, etc, it just rocks.

The Bad
The framework is useless in some cases. Since it is likely to have scripts and hidden fields in a page which cannot be located in an aa zone, problems begin to occur. Unfortunately we are using ibm jsf, where there is a script collector component on top of the h:form collecting scripts form components and outputs them in encodeEnd. In order to overcome the reloading problems of hidden fiels(e.g. state) and scripts, we have written a PreSendHandler class that takes the response and reloads the scripts-hidden fiels using javascript. We used nekohtml the parse the response buffer and dom inspector(for testing) to traverse the dom tree. However the idea failed because of the problems occured in programmatically manipulating scripts-hidden fields of the dom tree at runtime and ibm’s bad designed scripts. In addition one more disadvantage is, since the whole page is submitted, you should not get the performance you expect and the validation conversion errors are another question.

The Ugly
IBM’s approach to JSF, not related with AjaxAnywhere actually:)

What I can tell briefly about aa is; it rocks on simple cases I’ve mentioned but do not expect much on complex ones.


2 Responses to Ajax is everywhere with AjaxAnywhere

  1. Kenan says:

    My pair Cagatay has nicely summarized our 2-3 day struggle with ibm jsf components, ajax anywhere, html/xml dom etc. I want to add several points to this very informative blog entry.

    As Cagatay stated above, introducing aa in complex web pages would most probably fail, if the behaviour of components in refreshed zones depend on values of some other form elements (hidden fields) or scripts that are added dynamically during subsequent requests in the body of dom. You may solve some of those problems by writing PreSendHandler, or stating aa that it should refresh all the content of document.

    In our case document.all doesn’t work, as some ibm jsf components require dynamically added javascripts to be run during document onload event, but onload event never occurs with an ajax call.

    We also need to embedd an applet object into our ajaxied pages also, but refreshing all document with aa, causes applet to destroy each time, we made a request, and it is initalized again and again. This is unacceptable in terms of our business that is executed in our applet.

    Finally, I would say that, the idea behind ajax anywhere is very brilliant at least in theory,but in practice it needs some patchwork to make it work in complex web pages, and you may in some cases fail to realize your previous behaviour of those web pages.

    Another point is that ibm’s jsf components are really disguising in terms of their dynamically added scripts into the web pages. I think it is impossible to use ajax anywhere and ibm jsf components together because they require some javascript methods to be invoked while document is loaded each time.

    No ibm,no cry 🙂

  2. Sanjiv Jivan says:

    fyi you can use the getGlobalScriptsDeclarationsList function to specify the new variables/functions introduced in an AA zone :

    For example :

    ajaxAnywhere.getGlobalScriptsDeclarationsList = function(script) {
    return [“next”, “previous”];

    if the script includes the javascript functions next() and previous().

%d bloggers like this: