Overview
Provides a simple framework to integrate Ajax updates into a JSP/Servlet environment. It simplifies the updating of:
- Javascript GUI objects, eg. text and selections etc.
- InnerHTML.
- Executing javascript statements.
It contains the following:
- jajax.jar: Contains the implementation of the AjaxServlet, plus classes to implement your own
AjaxServlet request handler classes.
- jajax.js: Contains the single function, jajaxUpdate() which is the web page's interface to the servlet.
- A demo web application to demonstrate how it functions, and so that jajax.jar can be rebuilt.
All you need to do
- Add jajax.jar to your application.
- Configure the servlet as per the web.xml in the demo application.
- Create request handler classes as required for your pages. In general, one per Ajaxified page would be a good
idea. You could just add more classes under the 'webapp/src/jajax/handlers' directory so that
rebuilding the jar requires no extra work.
- Link the jajax.js script into any page that wants to make Ajax requests.
- In your Javascript event handler, make a call to the Javascript function 'jajaxUpdate(request)'.
jajaxUpdate() request format
The format of the request string is as follows:
<AjaxServlet>?class=<handlerClass>&jxid=<Id1>&jxid=<Id2>...[&jxdebug]
[+your own parameters]
Where: <Id1>, <Id2> etc are DOM targets in your current web page that need updating. The 'jxid' parameter name
can have a number appended to force a numeric order in which the targets are processes. If you append the
parameter 'jxdebug', then an alert() popup will display the page updates that will be applied as a result of the request.
Request processing
The servlet instantiates the handler class specified in the request, and then calls it for each of the
'jxid' parameters. The handler class
returns updates, which the servlet accumulates and then returns to the Javascript caller, jajaxUpdate(). Pretty much all the
caller does is pass the result to 'eval()' to perform the updates. If an error is thrown by the servlet then
it results in an alert() popup instead, describing the error. If the 'jxdebug' parameter was specified
in the request then an alert() popup displays the pages updates that are going to be applied. Simplicity itself :)