This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

how to bind data to a java class using Ajax and Controller?Page Title Module

before that, it was a spring webflow (swf 2.0.9.RELEASE, mvc 2.5.6.SEC02). Instead of ajaxcall(), I use form submit then trigger the webflow event. Directly call the registrationService.register(flowScope.Person) and the bind was automated.

In some reason, I need to use Ajax and call the service via controller. But... I had problem with data binding that's why I get the data from request object (posted data) then bind to Person class which is very tedious.

Comment

First of all, you are mixing new annotated controller strategy with old, deprecated controllers. This is bad, remove the "extends MultiActionController" and only use annotated @Controllers with <mvc:annotation-driven/>.

Once you got this done, and Spring mvc is properly configured with mvc:annotation-driven, I suggest you take a look at the DWR framework which integrates perfectly with Spring 3 and relieves you of the burden of JSON serialization-deserialization. In short, it lets you use Java objects directly in javascript: ajax call, json serialization, and all the "boring" stuff is handled automatically by the framework. I have this useful link that teaches how to integrate DWR with Spring so that you can use Spring annotations to mark DWR objects: