Announcement Announcement Module
No announcement yet.
Prevent redundant validation code Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Prevent redundant validation code

    Dear all,

    I'm quite new to Spring and ran into a problem, for which I could not find a satisfying solution.

    Say I have a Product1Validator and a Product2Validator, both implement Validator. And that I have SimpleFormControllers for both Product1 and
    Now, from the Product1 page, I also want to be able to create Product2's
    (from a quick popup, only filling in some required fields).

    I do not know how to use the Product2 validator from Product1's controller,
    so I added a static method validate(Product2) to Product2Validator.

    It works quite well, but the fact that I have a duplicate validate() method (the static and instance variant) does not feel good.
    I also cannot have the instance method call the static one here, because the instance method uses org.springframework.validation.Errors.

    Hope I made myself clear enough here ...
    And thanks for any design tips.