Announcement Announcement Module
No announcement yet.
Binding Error with multipe fields - parent/child - FormBackingObject Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding Error with multipe fields - parent/child - FormBackingObject

    I am having issues with SimpleFormController. On my JSP page, I have to show to two select boxes. One shows the filingYear. Based on the value selected here, second select box is populated with forms. Then for selected form, I have to display it's fields in grid(table) format.

    Here is my command class
    public class ReportFormFields {
    	private Long filingYear;//filingyear id value
    	private Long form; //form id value
    	//filing years - loaded from looup table
    	private List filingYears=
    		  	      new ArrayList(),
    	//forms loaded from database per filing year
    	private List forms=
    		  	      new ArrayList(),
    	//form fields loaded from db per form	
    	private List formFields =
    	  	      new ArrayList(),
    So, we have a master child relation like filingYear--->Form--->Fields.

    Here is my Controller Class that extend SimpleFormController.
    protected Object formBackingObject(HttpServletRequest request) throws ServletException{"*****formBackingObject() called***********"+isFormSubmission(request));
    	ReportFormFields reportFormFields = new ReportFormFields();
    	Long filingYearId = null;
    		filingYearId = ServletRequestUtils.getLongParameter(request, "filingYear");
    	}catch(ServletRequestBindingException ex){"filingYear is empty");
    	if(filingYearId != null){				
    		Long reportFormId = null;
    			reportFormId = ServletRequestUtils.getLongParameter(request, "form");
    		}catch(ServletRequestBindingException ex){"reportFormId is empty");
    		if(reportFormId != null){
    	}"ReportFormFields command object created: "+reportFormFields);
    	return reportFormFields;
    Now when I execute the program first time it works fine. Here is the flow on JSP.
    1. Shows the form with only one select box -- list of filing years. I select one filing year here
    2. Shows the form with 2 select boxes - one with list of filing years and second with list of forms. I select one form here.
    3. Now it shows the fields for that form in grid(table). Now I edit few fields on the table and save the data. It saves in the db.

    4. Now when I select a different value from the form (or the default value like 'Select One'), it throws an exception from the
    formBackingObject as formFields object is empty inside the command class.

    how can I come out of this problem. Do I need to add any custom property binding class. Or do I need to create the empty objects for formFields and add them to the command class.

    Also, filingyear list is a reference data to me. Can I add it in the referenceData()? Is this data is available for each request whenever the form is displayed.

    I have configured this form as sessionForm.

    Here is the trace of the exception:

    org.springframework.beans.NullValueInNestedPathException: Invalid property 'formFields[0]' of bean class []: Cannot access indexed value of property referenced in indexed property path 'formFields[0]': returned null
    	at org.springframework.beans.BeanWrapperImpl.getPropertyValue(
    	at org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(
    	at org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(
    	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValue(
    	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(
    	at org.springframework.validation.DataBinder.applyPropertyValues(
    	at org.springframework.validation.DataBinder.doBind(
    	at org.springframework.web.bind.WebDataBinder.doBind(
    	at org.springframework.web.bind.ServletRequestDataBinder.bind(
    	at org.springframework.web.servlet.mvc.BaseCommandController.bindAndValidate(
    	at org.springframework.web.servlet.mvc.AbstractFormController.handleInvalidSubmit(
    	at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(
    	at org.springframework.web.servlet.mvc.AbstractController.handleRequest(
    	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(