Friday, May 22, 2009

Auto Complete with AJAX

Its the first time that I have wet my hands with AJAX.(Reference - AJAX/JAVA)Prior to this I have been using .Net AJAX server side controls which internally wrap AJAX calls ,thus letting a user to deal only with facade.
There are numerous utilities to add auto-complete functionality to your site/application.I found them complex to use leading me to write one for myself.
It has three simple steps
1.Make asynchronous call to the server(handled by servlet) using XMLHttpRequest .
2.Get the required data in servlet and send the response as XML
3.Grab and process the data(display) in the front end when control is returned from the server.
The above three steps are common for any functionality achieved using AJAX.
The jsp page looks like this


In the above jsp if you have seen, on "onkeyupevent", function getData is called passing in the 4 parameters.The javascript file(its in text format) can be downloaded here
The servlet which handles the synchronous call made by jsp is shown below.The data to to be loaded is initialized by overriding the init method of the servlet(data retrieval will vary according to ones need)



That is pretty much.There is definitely a huge room for improvement but its gets the target rolling.

NOTE:The blogger.com parses everything ,so I had to include code in images.If anybody knows a better way to include code in blogspot, will be great.Thanks

No comments:

Assumptions of linear regression

There are some assumptions that a OLS (ordinary least square) or  linear regression makes about data and if these assumptions are not satisf...