Hii,,i have a problem when using multiple binding attribut. I have two class Person and address, they are have one-to-one relationship. This my view :
Name
Street
City
and this my controller to handle get method :
@RequestMapping(method = RequestMethod.GET)
private ModelMap displayForm(@RequestParam(value = “id”, required = false) Long id) {
Person person;
Address address ;
if (id == null) {
person = new Person();
address = new Address();
person.setAdress(address);
} else {
person = personDao.getById(id);
}
return new ModelMap(person);
}
if i request get method, everything is ok, but if i request post method i get problem, like this :
org.springframework.beans.NullValueInNestedPathExc eption: Invalid property ‘address’ of bean class [entity.Person]: Value of nested property ‘address’ is null
this is my controller to handle post method :
@RequestMapping(method = RequestMethod.POST)
private String proccessForm(@ModelAttribute(”person”) Person person, BindingResult resultPerson) {
newPersonValidator().validate(person, resultPerson);
if (resultPerson.hasErrors()) {
return “inputPerson”;
} else {
personDao.save(person);
return “listPerson”;
}
}
if i using velocity as view it’s ok, i get the address , i didn’t where is my wrong,could you give me some explanation, what is about view ? Thanks before…
Name
Street
City
and this my controller to handle get method :
@RequestMapping(method = RequestMethod.GET)
private ModelMap displayForm(@RequestParam(value = “id”, required = false) Long id) {
Person person;
Address address ;
if (id == null) {
person = new Person();
address = new Address();
person.setAdress(address);
} else {
person = personDao.getById(id);
}
return new ModelMap(person);
}
if i request get method, everything is ok, but if i request post method i get problem, like this :
org.springframework.beans.NullValueInNestedPathExc eption: Invalid property ‘address’ of bean class [entity.Person]: Value of nested property ‘address’ is null
this is my controller to handle post method :
@RequestMapping(method = RequestMethod.POST)
private String proccessForm(@ModelAttribute(”person”) Person person, BindingResult resultPerson) {
newPersonValidator().validate(person, resultPerson);
if (resultPerson.hasErrors()) {
return “inputPerson”;
} else {
personDao.save(person);
return “listPerson”;
}
}
if i using velocity as view it’s ok, i get the address , i didn’t where is my wrong,could you give me some explanation, what is about view ? Thanks before…
Comment