Announcement Announcement Module
Collapse
No announcement yet.
MVC Binding Help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MVC Binding Help

    Resolved!
    Needed to initialize my domain objects in my domain objects. My PhoneNumber objects needed initialized on my ContactInfo and ContactInfo on Client.

    I have a the following objects.

    Client which has a ContactInfo property which has 3 phone number properties.

    When I attempt to bind the values in my JSP for display it works fine here is a sample of how I am binding them.

    Code:
    <form:form method="post" commandName="client" action="addClient.htm">
    	<table>
    		<tr>
    			<td>First Name:</td><td><form:input path="firstName"/></td><td><form:errors path="firstName" cssClass="error"/></td>
    		</tr>
    		<tr>
    			<td>Home Phone:</td><td><form:input path="contactInfo.homePhone.phoneNumber"/></td><td><form:errors path="contactInfo.homePhone.phoneNumber" cssClass="error"/></td>
    		</tr>
    		<tr>
    			<td>Address:</td><td><form:input path="contactInfo.addressLine1"/></td><td><form:errors path="contactInfo.addressLine1" cssClass="error"/></td>
    		</tr>
    This works just fine. However when I attempt to submit my form I get the following error:

    Code:
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.NullValueInNestedPathException: Invalid property 'contactInfo' of bean class [springapp.domain.Client]: Value of nested property 'contactInfo' is null
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:488)
    	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:359)
    	org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
    	org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    	org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
    	org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67)
    	org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    	org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
    	org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
    	org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    	org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
    	org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105)
    	org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    	org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
    	org.springframework.security.ui.rememberme.RememberMeProcessingFilter.doFilterHttp(RememberMeProcessingFilter.java:116)
    	org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    	org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
    	org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
    	org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    	org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
    	org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:173)
    	org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    	org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
    	org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:271)
    	org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    	org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
    	org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89)
    	org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    	org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
    	org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
    	org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    	org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
    	org.springframework.security.concurrent.ConcurrentSessionFilter.doFilterHttp(ConcurrentSessionFilter.java:99)
    	org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
    	org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
    	org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:174)
    	org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:183)
    	org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:138)
    Here is the code that is attempting to do the binding (I never receive a result, it throws a null pointer before the result is returned).

    Code:
    	@RequestMapping(value="/client/addClient.htm", method=RequestMethod.POST)
    	public String insertClient(@ModelAttribute Client client, BindingResult result) {
    		// Call to the SimpleClientManager to insert a client and return to the proper view
    		// Map client object with proper fields from request
    		
    		new ClientValidator().validate(client, result);
    
    		if(result.hasErrors()) {
    			return "newClient";
    		}
    		
    		manager.insertClient(client);
    		
    		return "redirect:/client/clients.htm";
    	}
    I have tried everything I can think of, how do I keep the ContactInfo and PhoneNumber objects from being null?
    Last edited by immortal_hero; Sep 26th, 2008, 08:36 PM.

  • #2
    Just in case it helps:

    Client domain object:
    Code:
    package springapp.domain;
    
    import java.io.Serializable;
    
    public class Client implements Serializable {
    
        private String firstName;
        private String lastName;
        private Long clientId;
        private ContactInfo contactInfo;
     
        public String getFirstName() {
    		return firstName;
    	}
    
        public void setFirstName(String firstName) {
    		this.firstName = firstName;
    	}
    
        public String getLastName() {
    		return lastName;
    	}
    
        public void setLastName(String lastName) {
    		this.lastName = lastName;
    	}
    
    	public Long getClientId() {
    		return clientId;
    	}
    
    	public void setClientId(Long Id) {
    		this.clientId = Id;
    	}
    
    	public ContactInfo getContactInfo() {
    		return contactInfo;
    	}
    
    	public void setContactInfo(ContactInfo contactInfo) {
    		this.contactInfo = contactInfo;
    	}
    }
    ContactInfo domain object:
    Code:
    package springapp.domain;
    
    public class ContactInfo {
    	private String addressLine1;
    	private String addressLine2;
    	private String addressLine3;
    	private String city;
    	private String state;
    	private Long zip5;
    	private Long zip4;
    	private String email;
    	private PhoneNumber homePhone;
    	private PhoneNumber workPhone;
    	private PhoneNumber cellPhone;
    	
    	public String getAddressLine1() {
    		return addressLine1;
    	}
    	public void setAddressLine1(String addressLine1) {
    		this.addressLine1 = addressLine1;
    	}
    	public String getAddressLine2() {
    		return addressLine2;
    	}
    	public void setAddressLine2(String addressLine2) {
    		this.addressLine2 = addressLine2;
    	}
    	public String getAddressLine3() {
    		return addressLine3;
    	}
    	public void setAddressLine3(String addressLine3) {
    		this.addressLine3 = addressLine3;
    	}
    	public String getCity() {
    		return city;
    	}
    	public void setCity(String city) {
    		this.city = city;
    	}
    	public String getState() {
    		return state;
    	}
    	public void setState(String state) {
    		this.state = state;
    	}
    	public Long getZip5() {
    		return zip5;
    	}
    	public void setZip5(Long zip5) {
    		this.zip5 = zip5;
    	}
    	public Long getZip4() {
    		return zip4;
    	}
    	public void setZip4(Long zip4) {
    		this.zip4 = zip4;
    	}
    	public String getEmail() {
    		return email;
    	}
    	public void setEmail(String email) {
    		this.email = email;
    	}
    	public PhoneNumber getHomePhone() {
    		return homePhone;
    	}
    	public void setHomePhone(PhoneNumber homePhone) {
    		this.homePhone = homePhone;
    	}
    	public PhoneNumber getWorkPhone() {
    		return workPhone;
    	}
    	public void setWorkPhone(PhoneNumber workPhone) {
    		this.workPhone = workPhone;
    	}
    	public PhoneNumber getCellPhone() {
    		return cellPhone;
    	}
    	public void setCellPhone(PhoneNumber cellPhone) {
    		this.cellPhone = cellPhone;
    	}
    
    }
    PhoneNumber domain object:
    Code:
    package springapp.domain;
    
    public class PhoneNumber {
    	private String phoneNumber;
    	private String ext;
    	private String numRegX = "[^0-9]";
    	
    	public String getPhoneNumber() {
    		return phoneNumber;
    	}
    	public void setPhoneNumber(String phoneNumber) {
    		this.phoneNumber = phoneNumber;
    	}
    	public String getExt() {
    		return ext;
    	}
    	public void setExt(String ext) {
    		this.ext = ext;
    	}
    	public String getNumRegX() {
    		return numRegX;
    	}
    	public void setNumRegX(String numRegX) {
    		this.numRegX = numRegX;
    	}
    }

    Comment


    • #3
      In your client class Initialize ContactInfo

      private ContactInfo contactInfo = new ContactInfo();

      Comment


      • #4
        Originally posted by tdhaayushverma View Post
        In your client class Initialize ContactInfo

        private ContactInfo contactInfo = new ContactInfo();
        So I figured out after 2 hours a banging my head against the wall... hate stupid problems like this...

        Comment

        Working...
        X