I believe after Spring blog announced Ajax integration with Spring MVC, many of us are excited.
The best part is add @ResponseBody in your controller and Spring will create JSON response for you.
@RequestMapping(value=”/testJquery”, method=RequestMethod.GET)
public @ResponseBody List getProperResponse(@RequestParam String name) {
}
jquery autocomplete
() expects json response in the following format.
{
label: blablabla
value: blablabla
}
So your ResponseBean should have following annotations and field names
ResponseBean{
@JsonProperty(value=”label”)
String name;
@JsonProperty(value=”name”)
String value;
}
You need entry in your dispatcher-servlet.xml so that Jackson Jars are invoked to formulate your ajax response.
And you need jackson jars in app server classpath.
(jackson-core-asl-1.9.5 and jackson-mapper-asl-1.9.5)
Install firbug to see your json response. If its improper, it means that jackson jars are not being picked up by your Spring and you may need to place them in your classpath.
Thats all for now. Happy coding with Spring
Ajax, JQuery, integration, Spring, font