I'm working on a small Spring MVC application and I'm trying to create a dynamic form using Velocity, Spring and jQuery.
I followed that article, of course with some changes :
http://eggsylife.co.uk/2009/11/30/sp...ists-and-ajax/
My Person class has a List of phones (it's a LazyList, with AutoPopulatingList it doesn't work)
My PersonFormController methodCode:.... @OneToMany(cascade = CascadeType.ALL, mappedBy = "person", fetch = FetchType.EAGER, targetEntity = Phone.class) private List<Phone> phones; public Person() { phones = LazyList.decorate (new ArrayList<Phone>(), new InstantiateFactory(Phone.class)); } ....
and in my personForm.vm file in one form there are :Code:@RequestMapping(method = RequestMethod.GET) public String showPersonForm(ModelMap modelMap) { Person person = new Person(); modelMap.addAttribute(person); return "personForm"; }
1. Person adding #springBind
2.And Phone addingHTML Code:<td>Name</td> <td> #springBind("person.name") <input type="text" name="name" value="$!person.name"> <td width="60%"> <font color="red">$!{status.errorMessage}</font> </td> </td>
I am able to produce new inputs for phone adding with AJAX and jQuery just like in an article posted above and it works fine.HTML Code:<table id="tablePhones"> <tr> <td>Number</td> <td> #springBind("person.phones[0].number") <input name="person.phones[0].number" size="40" /> </td> <td><a href="#" id="add">Add new phone</a></td> </tr> </table>
So now when I fill all fields in my PersonFormController there is a method
Validation is fine and... only the Person is persisted and always one Phone with all null values. What do I need to change to fully persist all phones with current person? Could anyone help me with this? I am trying to figure it out for a long time..Code:@RequestMapping(method = RequestMethod.POST) public String addPerson(@ModelAttribute("person") Person person, BindingResult result) { personValidator.validate(person, result); if (result.hasErrors()) { return "personForm"; } else { personDao.saveOrUpdate(person); return "redirect:index.htm"; } }
Maybe You need more information or my code?
Thanks
Dawid


Reply With Quote