Results 1 to 7 of 7

Thread: Value of nested property 'contactAddress' is null

  1. #1

    Angry Value of nested property 'contactAddress' is null

    I have been trying everything now to get this to work. Please help!

    I have object Company

    That object has a property contactAddress that is a instance of the class Address.


    Code:
    public class Company {
    	
            private String name;
    	private Address contactAddress;
    
    }
    Code:
    public class Address {
    	
            private String street;
    
    }
    I am trying to post this to my controller and insert it into the db.

    the JSP is as follows:

    Code:
    <form:form commandName="company" action="home-add-company">
    				
    <form:input path="name" cssClass="validatedinput"/>
    
    <form:input path="contactAddress.street"/>
    
    </form:form>

    I have a couple of PropertyEditorSupport classes taking care of the transformation, and that is working fine if the objects are not nested.

    I instantiate the objectgraph before in the controller before showing the form, and if I set the value of contactAddress's street, the value shows up in the form.

    So that seems to work.

    But when I post the form, I get the error:


    Code:
     Invalid property 'contactAddress' of bean class [com.ww.dao.domain.Company]: Value of nested property 'contactAddress' is null

    Could someone please tell me what this could be!?

    Thanks!

  2. #2
    Join Date
    Nov 2006
    Location
    Columbus, OH
    Posts
    143

    Default

    sore,

    Perhaps you need to initialize contactAddress in the Company class default constructor or in the formBackingObject method of your form controller? Ie.,

    Code:
    public Company() {
         super();
         ...
         contactAddress = new Address();
    }
    See http://forum.springsource.org/showpo...13&postcount=3 for more information.

    Regards,

    Joshua Preston.

  3. #3
    Join Date
    Jan 2006
    Location
    Seattle, Washington
    Posts
    467

    Default

    I assume you actually have public getters/setters on those POJOs reflecting the same property names as the instance variables?

    It might be worth running this in the debugger, setting breakpoints on both the setter and getter for contactAddress and street. That might give you some useful information.

  4. #4

    Default

    Thank you for your help.

    For others with this problem; none of the above suggestions helped me, instead I changed the form to use a command with company and address as different objects and joining them "by hand" after the form was submited.

    I never got the nesting to work, I dont know whats wrong with it.

  5. #5
    Join Date
    Jan 2006
    Location
    Seattle, Washington
    Posts
    467

    Default

    It might provide useful information if you set breakpoints in your constructor and the contactAddress getter and setter, and then watch what happens when you POST. I can't tell exactly what you will find, but it might give you a clue.

  6. #6

    Default

    This seems to be dead for a while, however for the benefit of anyone who runs into this problem like I did.
    If you change the default constructor for the containing class (Company) and rely on tc or your spring container to just remember the current session, the current flow will not restart and all the flow scope variables will not be re-instantiated.
    I had the same problem, changed the default constructor of my containing class but no change. Then killed my current browser session and it worked! Those breakpoints showed me the way. Thanks

  7. #7
    Join Date
    Dec 2010
    Posts
    1

    Default

    I ran into the same problem and I believe I fixed this using a serialVersionUID like
    private static final long serialVersionUID = 6848111881479954820L;

    --
    Regards
    Milind

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •