Announcement Announcement Module
No announcement yet.
[ASK] org.springframework.beans.NullValueInNestedPathExc eption: Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • [ASK] org.springframework.beans.NullValueInNestedPathExc eption:

    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 :



    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();
    } 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 {;
    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…

  • #2

    There is probably a reference to a field in your address object from your view (probably jsp) that is null. You need to give it a value. I believe velocity treats null values as empty strings (or just "") by default, which is why you don't get the error when using it. JSP is a little different. The way I've always done it is set the default values for all sub objects to a non-null value in either the default constructor or use a static stub of the object with default values set.

    If it is indeed a null address object, you're probably getting this error when you're loading a person with the personDao.getById(id) method and the address is not being set also. Not sure if you're using a persistence layer or not (like hibernate or sqlmaps), but that's something else to check.

    On that note, you should also make sure your method is persisting the address object in addition to the person.

    Hope that helps,


    • #3
      Thanks for your reply, i try to fix it now... many thanks...