Results 1 to 3 of 3

Thread: Validator and SimpleFormController

  1. #1
    Join Date
    Jul 2006
    Posts
    21

    Thumbs up Validator and SimpleFormController

    Just want an opinion here.

    I have a number of simple validations to perform on some trivial screens.
    They only have a few fields that require input validation.

    Would there be a downside of implementing the Validator interface within a SimpleFormController Class?
    This would eliminate the need for an additional class with only a few lines of code.

    So I would have something like

    class SomeFormController extends SimpleFormController implements Validator {

    public void validate(Object obj, Errors errors) {
    // do my form validation
    }

    }

    Any thoughts would be appreciated.

  2. #2
    Join Date
    Jul 2006
    Location
    Wheaton, IL
    Posts
    32

    Default

    I guess I would ask what the benefit is of having one less class.

    To me the potential issue is that you can't use that Validator elsewhere. Well, you could, I suppose, but you might not think to given it being named SomeFormController. So this could impact scalability and maintainability, but I don't think it wouldn't work.

  3. #3
    Join Date
    Jul 2006
    Posts
    21

    Default

    I agree that it makes the class less reusable, and I wouldn't try to reuse the entire controller just to do validation.
    But the validator is already bound to the form for the controller, so I don't know that there is really much reuse potential anyway.

    In addition, you can always override the Validator anyway by injecting a new Validator.

    I would define the SomeFormController as the validator in the constructor as so:

    public SomeFormController {
    setValidator(this);
    }

    So upon startup, Spring could override this behavior by injecting a different Validator.

    The approach does work BTW. I just wanted opinions as to whether or not it is considered good form.

    Thanks for the reply!

Posting Permissions

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