Results 1 to 4 of 4

Thread: binding before validating

  1. #1
    Join Date
    Dec 2004
    Posts
    4

    Default binding before validating

    I noticed that SimpleFormController class has some inherited methods like onbind() and onBindAndValidate(). Why does it doing the binding before the validation? Is it more logical to do validation first, if there is errors, then no need to do further binding. I have a command object that has some primitive type like int and long. It generates some NumberFormatException because user submit null value, which I intend to catch it in validatiion method.

    Is it a required that all fields in Command Object have to be an Object type, no primitive?

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Why does it doing the binding before the validation?
    Binding is mapping the submitted data to your domain object. Spring will automaticaly validate type mismatch errors for you. The validation step is for validating the domain object. This can only occur after binding.

    It generates some NumberFormatException because user submit null value, which I intend to catch it in validatiion method
    Again, Spring does this automatically for you. You can tidy up the message with a message property like typeMismatch.java.util.Date=invalid date.

  3. #3
    Join Date
    Dec 2004
    Posts
    4

    Default

    Thanks a lot for replying. Is there any particular reason that we don't validating before binding? I don't understand the design logic here. In this case, I hope all the validation and its error message can be done and specified in one place, that's the validator class. Why Spring does this checking AUTOMATICALLY for me in the first place (type mismatch check in binding)?

    Anybody else who defines a domain/command object which has some primitive type fields? This got to be a very common practice. I look into the jpetstore example, no primitive type is used.

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    I hope all the validation and its error message can be done and specified in one place, that's the validator class
    The validator class operates on a domain object. If the binding fails (type mismatch) you don't have a valid domain object to validate. Spring is saving you some work by doing the type validation automatically - you can specify the error message - what else do you want to customise?

    Anybody else who defines a domain/command object which has some primitive type fields?
    Yes - it works as expected.

Similar Threads

  1. Enum binding not showing default
    By ge0ffrey in forum Swing
    Replies: 3
    Last Post: Jan 23rd, 2006, 09:08 AM
  2. Binding and validating hibernate entities
    By theguama in forum Data
    Replies: 4
    Last Post: Sep 20th, 2005, 04:31 AM
  3. Replies: 7
    Last Post: Sep 13th, 2005, 01:45 AM
  4. Replies: 0
    Last Post: Jan 6th, 2005, 08:19 AM
  5. Replies: 2
    Last Post: Aug 17th, 2004, 04:16 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
  •