Im wondering whats the best way of using ajax with spring mvc. At the minute i have a view object that I want to update when the user toogles a dropdown box and update some properties. The problem is these fields don't bind properly after an ajax request adds them to the page. When i refresh the page its fine though. Is there an issue with ajax and @sessionAttributes with spring mvc. Do ajax and spring work on different sessions maybe?. Im just looking a general idea about how to integrate both ajax and spring.
Asked
Active
Viewed 665 times
1 Answers
1
One, really nice solution is the integration of Spring MVC with Jackson.
Jackson is a cool framework for read and write JSON content, and the integration with spring is fantastic. The serialization and desrialization process is transparent for the developer, your controller receives the deserialized object as parameters and returns java objects as result. Jackson does the serialization of the result object and deserialization of the parameters.
You can for example have a controller with the following structure:
@Controller
@RequestMapping("/path/to/it")
public class JSONController {
@RequestMapping(value="{name}", method = RequestMethod.GET)
public @ResponseBody ComplexStructure getJSONData(@PathVariable String name) {
return new ComplexStructure(10, 20, "some other value");
}
}
You can take a look here to have an idea regarding configuration and find some samples here and here

Community
- 1
- 1

Francisco Spaeth
- 23,493
- 7
- 67
- 106
-
Does this also help with returning a location to a tile for example? – john Jun 26 '12 at 08:01
-
sorry, I didn't get the point, could you clarify a bit your question? – Francisco Spaeth Jun 26 '12 at 08:03