The following online presentation/demo about Exadel‘s new Ajax4jsf component library sums up nicely why you shouldn’t try hacking your own AJAX code but use an AJAX enabled JSF component library (like Ajax4jsf and others) instead:
In short: It’s all about ensuring good maintainability and hence transparency (in the sense of encapsulation and information hiding) while delivering a rich user experience nonetheless. Handcrafted, customized AJAX pages quickly tend to get complex and confusing and hardly ever follow important software architecture principles like modularization, abstraction, loose coupling, information hiding and encapsulation. The result is a piece of code that meets the consumer expectations at best (interactivity, responsiveness, etc.) but is very difficult to maintain (as server- and client-side code, customized and “standardized” code are wildly mixed). Using an AJAX enabled JSF components framework instead transparently hides the AJAX part of the code from the programmer by encapsulating it in JSF components. It’s thus possible to provide rich AJAX functionality by writing JSF server-side code as usual without needing to care about the internals of AJAX at all. If none of the existing components deliver AJAX-wise what customers expect, simply extend and customize the best matching component or write your own highly customized JSF component from scratch. JSF’s flexibility and sophisticated architecture makes this possible. Doing customization like this won’t clutter up your server-side code and will thus keep it maintainable and scalable.
While I haven’t tried this particular AJAX enabled JSF component framework yet and can’t comment on its implementation at this point (here’s a nice architectural overview of the different approaches how to combine AJAX and JSF from a framework developer’s view), the sprouting of AJAXified JSF component frameworks is a clear indication that more and more developers are becoming aware of the maintainability issues inherent to plain AJAX hacking.