I have been fiddling with this code fragment from past few hours but I am unable to understand how jQuery's autocomplete UI works. I followed this tutorial http://viralpatel.net/blogs/tutorial-create-autocomplete-feature-with-java-jsp-jquery/ I used same example but instead of sending request to a JSP, I used a servlet. The request reaches the servlet "Fetcher", it executes as well but nothing is returned to the page. Here's the code.
public class Fetcher extends HttpServlet {
[...]
List<String> countryList = new ArrayList<String>();
String param = request.getParameter("term");
countryList.add("USA");
countryList.add("Pakistan");
countryList.add("Britain");
countryList.add("India");
countryList.add("Italy");
countryList.add("Ireland");
countryList.add("Bangladesh");
countryList.add("Brazil");
countryList.add("United Arab Emirates");
PrintWriter out = response.getWriter();
response.setContentType("text/plain");
response.setHeader("Cache-Control", "no-cache");
for(String country : countryList){
out.println(country);
}
[...]
}
Javascript fragment in HTML:
<script>
$(function() {
$( "#tags" ).autocomplete({
source: "Fetcher"
});
});
</script>
HTML form:
<label for="tags">Tags: </label>
<input id="tags" />
The examples on the page seems written for a pro in jquery, http://jqueryui.com/autocomplete/#default . Please, could someone tell how exactly it works, so that I can use it in other places.