Hi Team,
I have the following form which I need to submit.
Code:<form method="POST" action="registerUser.html"> <table border="0" cellspacing="5" cellpadding="0"> <tr> <td>First Name :<input type="text" name="firstname"></td> </tr> <tr> <td>Last Name :<input type="text" name="lastname"></td> </tr> <tr> <td>Street :<input type="text" name="address.street"></td> </tr> <tr> <td>State :<input type="text" name="address.state"></td> </tr> </table> </form>
The data is validated and then then passed on the controller.
Configuration file
Code:<bean id="addressValidator" class="com.skyline.foundation.web.AddressValidator"/> <bean id="userRegistrationValidator" class="com.skyline.foundation.web.UserRegistrationValidator"> <constructor-arg><ref bean="addressValidator"/></constructor-arg> </bean> <bean id="registerUserController" class="com.skyline.foundation.web.RegisterUserController"> <property name="sessionForm"><value>true</value></property> <property name="commandName"><value>user</value></property> <property name="commandClass"><value>com.skyline.foundation.model.User</value></property> <property name="validator"><ref bean="userRegistrationValidator"/></property> <property name="formView"><value>registerUser</value></property> <property name="successView"><value>registerSuccess.htm</value></property> <property name="userService"><ref bean="userService" /></property> </bean>
The user object is as defined below and has the setter and getter for the attributed
The Address class is as belowCode:public class User implements Serializable, Comparable { /** * */ private static final long serialVersionUID = 1L; private Long id = null; private int version; private String firstname; private String lastname; private Address address;
Code:public class Address implements Serializable { /** * */ private static final long serialVersionUID = 1L; private String street; private String country;
When ever I am submitting my form I am getting the following exception
Code:org.springframework.beans.NullValueInNestedPathException: Invalid property 'address' of bean class [com.skyline.foundation.model.User]: Value of nested property 'address' is null org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:419) org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:394) org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:600) org.springframework.beans.AbstractPropertyAccessor.setPropertyValue(AbstractPropertyAccessor.java:49) org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:74) org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:517) org.springframework.validation.DataBinder.doBind(DataBinder.java:419) org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:147) org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:108) org.springframework.web.servlet.mvc.BaseCommandController.bindAndValidate(BaseCommandController.java:369) org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:248) org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153) org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:45) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:820) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:755) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:360) javax.servlet.http.HttpServlet.service(HttpServlet.java:709) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Please help me how to bind the form with a complex command object.
Regards
Om


Reply With Quote
Enjoy
