Results 1 to 2 of 2

Thread: onBindAndValidate vs Validator

  1. #1

    Default onBindAndValidate vs Validator

    Is there a benefit to implementing Validator as opposed to just creating an onBindAndValidate method in the FormController?

  2. #2
    Join Date
    Aug 2004
    Location
    Mount Joy, PA
    Posts
    34

    Default

    Personally, I like to put all of my validation code into separate validator classes. Validation code is potentially reusable, and having it in a separate class allows me to reuse it if needed. If the validation depends on resources that are not otherwise needed in the controller then your application and/or servlet context will be more intuitive and self documenting if you wire such dependencies into a separate validator object rather than wiring them all into the controller.

    Now onto a more subjective opinion. I think validation is a separate concern from the role of the controller. Therefore, your application will tend to be cleaner if you separate all validation logic into a separate class and let the controller just worry about controlling--it's hard enough to keep business logic out of the controller without having validation logic in there too. The tendency, especially for those new to MVC, is to write monolithic controllers containing lots of business logic. This really bites later when it's time to refactor the app (e.g. to move to a different MVC package or data persistence technology).

    On the other hand, if your validation logic is very simple onBindAndValidate may be a better way to go so you don't end up with a lot of trivial classes cluttering up your object space.
    ~ Daniel Miller

Similar Threads

  1. FormAction or Validator for this situation?
    By tortuga in forum Web Flow
    Replies: 3
    Last Post: Jul 20th, 2005, 05:19 AM
  2. Replies: 3
    Last Post: Apr 5th, 2005, 09:20 PM
  3. Replies: 1
    Last Post: Feb 23rd, 2005, 06:40 AM
  4. Replies: 2
    Last Post: Nov 25th, 2004, 03:41 PM
  5. Replies: 1
    Last Post: Nov 25th, 2004, 11:08 AM

Posting Permissions

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