class:
controller:Code:public class Person implements Serializable { private int id; private String name; private List<Address> addresses; }
upon ajax call, I serialize the form elements one by one.Code:public class PersonController extends MultiActionController { private RegistrationService registrationService; @RequestMapping(method = RequestMethod.POST) public void register(HttpServletRequest req, HttpServletResponse res) { Person person = bindPostedData(req); registrationService.register(Person); ....... } private Person bindPostedData(HttpServletRequest req) { Person person = new Person(); person.setId(req.getParamter("id")); person.setName(req.getParamter("name")); ...... return person; } }
example JS (register button click event):
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.Code:var person = { "id": $("#person\\.name").val(), "name": $("#person\\.name").val(), ..... } ajaxcall(person);
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.
Please guide me or give me some hints to investigate.
Thanks in advanced.



Reply With Quote
