Creating an Autocomplete Textbox
One of the cool tags of AjaxTags is ajax:autocomplete. We will use this tag in this following JSP example.
<fieldset>
<legend>ajax:autocomplete example</legend>
<form>
<label for="country">Country Name: </label>
<input type="text" name="country" id="country"/>
</form>
<ajax:autocomplete
source="country"
target="country"
baseUrl="country_list.view"
parameters="country={country}"
className="autocomplete"
minimumCharacters="1"/>
</fieldset>
Our objective here is to make an autocomplete for the textbox country. We have a Servlet which will return a list of country names that starts with the value of country textbox.
This tag must appear after the form tag. Attribute source is the id of the input textbox. Attribute target is the id of the target textbox; target may be same as source or different than source. Attribute baseUrl specifies the server side code. One important attribute for ajax:autocomplete is minimumCharacters, it specifies character count after which AjaxTags will request for country_list.view with country name as a parameter.
.autocomplete {
position: absolute;
color: #333333;
background-color: #ffffff;
border: 1px solid #666666;
font-family: Arial;
overflow: hidden;
}
This is a sample style sheets entry for ajax:autocomplete.
Now we need to create the server response for this tag. Sample response would be like following. Assuming we entered ‘A’ in country textbox.
<?xml version="1.0" encoding="UTF-8"?>
<ajax-response>
<response>
<item>
<name>America</name>
<value>America</value>
</item>
<item>
<name>Angola</name>
<value>Angola</value>
</item>
<item>
<name>Austria</name>
<value>Austria</value>
</item>
<item>
<name>Australia</name>
<value>Australia</value>
</item>
</response>
</ajax-response>
In Part I, I discussed AjaxTags helper classes. First we need to add following import statements in your Servlet code.
import org.ajaxtags.helpers.*;
import org.ajaxtags.servlets.*;
Next you need to ... [Read Full Article]
click here to see original article or to find similar articles
HEADLINES
Edwards to emerge from seclusion for speech
In a return to the public stage, John Edwards has confirmed plans to talk politics a month after admitting to an extramarital affair. But his wife won't be at his side.
Australian police clear Indian doctor of involvement in terror
(AFP)
AFP - Australian police have cleared an Indian doctor of involvement in failed bomb attacks in Britain last year after a bungled 14-month probe that is now the subject of a judicial inquiry.
Consumer spending flags, but confidence rises
(Reuters)
Reuters - Personal income tumbled unexpectedly
in July and inflation-adjusted spending shrank as government
economic stimulus waned, but consumer spirits rose this month,
a hint the economy may muddle through its woes.