Results 1 to 7 of 7

Thread: SimpleFormController Errors instance first time into form.

  1. #1
    Join Date
    Oct 2004
    Posts
    8

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Toronto, ON, Canada
    Posts
    101

    Default Re: SimpleFormController Errors instance first time into for

    Quote 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.

  3. #3
    Join Date
    Aug 2004
    Location
    Paris
    Posts
    43

    Default

    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 ?

  4. #4
    Join Date
    Oct 2004
    Posts
    8

    Default

    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.

  5. #5
    Join Date
    Aug 2004
    Location
    Paris
    Posts
    43

    Default

    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.

  6. #6
    Join Date
    Aug 2004
    Location
    Carlisle, UK
    Posts
    184

    Default

    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.
    Chris Harris
    Carlisle, UK

  7. #7
    Join Date
    Oct 2004
    Posts
    8

    Default

    ah, thank you. That makes sense now!

Similar Threads

  1. Replies: 17
    Last Post: Jan 2nd, 2007, 01:43 PM
  2. Replies: 4
    Last Post: Oct 5th, 2005, 11:04 AM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. Replies: 6
    Last Post: May 25th, 2005, 01:56 AM
  5. DefaultAdvisorAutoProxyCreator skipping beans
    By youngm in forum Container
    Replies: 6
    Last Post: Apr 12th, 2005, 04:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •