Announcement Announcement Module
No announcement yet.
SimpleFormController creates bean with twice the value during form sumission Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • SimpleFormController creates bean with twice the value during form sumission

    I am using SimpleFormController for creating a form and then submitting the form.

    I have a FBO that is initialized by formBackingObject()

    protected Object formBackingObject(HttpServletRequest request) throws Exception {
     Order order = new Order();
     return order;
    Lets say, At this point the value of symbol is "CSCO"

    The JSP looks like this,

    <form:form method="post" action="" commandName="Order" >   
        		<td>Enter Symbol</td>
            		<form:input  path="symbol"  />
                    <font color="red"><form:errors path="symbol" /></font>
    When the form is displayed, the input text box is pre-populated with text "CSCO"

    Until now everything is fine...

    Now when the user submits the form.

    In the onSubmit() method, The value of symbol is "CSCO,CSCO"

    This is very bad.

    In case the user changes the input text box value to "XXX",
    I get "CSCO,XXX" for symbol.

    Is this expected behavior?
    If so, what is the right approach for handling the form?

  • #2
    Read this.


    • #3
      It doesn't help if clear the formbacking object, because I the command already contains what the user supplied + value from formbacking object.

      The issue is, I am using the same controller for displaying the form and process the form. The URL is also the same.

      		ServletRequestDataBinder binder = createBinder(request, command);
      		BindException errors = new BindException(binder.getBindingResult());
      		if (!suppressBinding(request)) {
      			onBind(request, command, errors);
      			if (this.validators != null && isValidateOnBinding() && !suppressValidation(request, command, errors)) {
      				for (int i = 0; i < this.validators.length; i++) {
      					ValidationUtils.invokeValidator(this.validators[i], command, errors);
      			onBindAndValidate(request, command, errors);
      		return binder;
      So, the binder.bind() method actually adds the value from request again!

      Once solution would be to create a different url for posting the form,


      • #4
        The command object IS the formBackingObject. The first time the form is submitted, the value of the command object is saved in session, then when the second time the form is displayed (after onSubmit) the value of the text field is picked up from the command object which is picked up from the session which is why it is neccessary to clear it.