Announcement Announcement Module
Collapse
No announcement yet.
SimpleFormController Errors instance first time into form. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SimpleFormController Errors instance first time into form.

    I have a jsp page that is working with the SimpleFormController. Everything works fine, but now I want to display the errors. I get the error message "add the Errors model to your ModelAndView via errors.getModel" when I try to use the tag:

    <spring:bind path="uploadCommand.*">
    <c:forEach items="${status.errorMessages}" var="error">
    Error code: <c:out value="${error}"/><br>
    </c:forEach>
    </spring:bind>

    The problem is I do not have a command object the first time into the jsp page because the user has not entered anything yet. I assume I do not need one version of the form to submit and one to display errors? Or am I supposed to go through a Controller just to set the BindException errors on the model? If so which Controller would I use?

  • #2
    Re: SimpleFormController Errors instance first time into for

    Originally posted by jeffjj
    The problem is I do not have a command object the first time into the jsp page because the user has not entered anything yet.
    You should have a command object because that is what you create in the formBackingObject() method of your SImpleFormController subclass.

    S.

    Comment


    • #3
      just send an empty object on your formbacking object. I don't know how you manage to not send any command object to a simpleformcontroller, since the formbacking does not allow you to return null ?

      Comment


      • #4
        Thats where my confusion lies. I do not go through my SimpleFormController the first time into the form. I thought I only went through my SimpleFormController when I hit the submit button so that I can process the data and move on.

        After re-reading the workflow of the SimpleFormController I see the formBackingObject() is step 2 and step 7 says "Model gets exposed and view gets rendered, to let the user fill in the form." But how does the SimpleFormController know that I want to render the form for the first time and I am not doing a submit to process the data?

        Thanks for your help! I totally appreciate it.

        Comment


        • #5
          First time, you render the view with an empty object, or with an object with init values ( like default, or values read from the database). Then when you click submit, this object is binded with the new values, entered by the user. In the submit method, you can retrieve this object updated, and you can for exemple store it somewhere. After that, you go by default to the finishView.
          You go throught the controller, each time you request his url, but you go on the submit method, only, if you post the form, with valid data.

          Comment


          • #6
            But how does the SimpleFormController know that I want to render the form for the first time and I am not doing a submit to process the data?
            It makes this decision based on the result of calling isFormSubmission() (a method of AbstractFormController). The default implementation returns false if the request is a GET, and true if it's a POST. You can override this if you want.
            See the javadoc for more details.

            Comment


            • #7
              ah, thank you. That makes sense now!

              Comment

              Working...
              X