Announcement Announcement Module
Collapse
No announcement yet.
How to avoid rebinding form field values on error? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to avoid rebinding form field values on error?

    Hi. When you have a web form backed by a command object, the values in the form fields are filled in from the values in the bound command object. Thus, when there is a binding error, the value in the command object is displayed rather than the value the user entered. This can be annoying for the user as all the data he has entered vanishes if there is an error in just a single form field. Is there any way to avoid this?

    It would be nice if you could get e. g. $status.errorMessages (in velocity) to evaluate to the bound fields validation and binding error messages, and at the same time get $command.field to evaluate to the value the user entered rather than the value in the command object. Is something like this possible?

  • #2
    when there is a binding error, the value in the command object is displayed rather than the value the user entered
    This isn't the way it's supposed to work (and not the way it behaves in my apps) - are you sure you're not doing something incorrectly?

    Comment


    • #3
      I am passing the values to be rendered through a formatting method in a velocity tool class. The value the user entered is lost because the value passed to the formatting function during rendering of the velocity template is the value in the form backing object and not the value the user entered. I see that the value is not lost when it is not passed through the formatting function. I don't know if this is because i'm doing something wrong, suggestions? Am i supposed to do seomething "by hand" to retrieve the entered value?

      A related question: In one of my pages a complex form is constructed by the user using javascript. If there is a binding/validation error when the form is submitted, the original form is returned to the user instead of the one he has constructed. Are there any strategies for avoiding re-rendering part of a page?

      Comment


      • #4
        I'm not sure if this is the problem, but are you using the method, "showForm(...)", rather than the "formBackingObject(HttpServletRequest request)" method of the SimpleFormController?

        That might solve the binding problem.

        Your question about preserving dynamically built forms is a good one. I have the same problem.
        Last edited by redtiger; Jun 9th, 2006, 04:08 PM.

        Comment


        • #5
          I looked at preserving dynamically built forms, and I believe that the problem with losing dynamic fields is not an issue with Spring. Even a dynamic form that is not in the Spring container will lose its dynamic fields when it is submitted. The only way to preserve them is to set a variable in your command class so that the form can be rebuilt by checking the command's variables.

          Comment

          Working...
          X