Announcement Announcement Module
Collapse
No announcement yet.
Conceptual question about validation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Conceptual question about validation

    I have a "how is this supposed to work question" regarding Web MVC.

    If I am using SimpleFormController to display an object, I understand that I am supposed to implement the "Validator" interface to create an object that will check the incoming data to ensure it is correct.

    My trouble with this is that validation occurs after binding. Doesn't this violate the principal that my business object should never be in an invalid state?

    I guess I could make my command objects separate from my business objects, but it seems like I would end up duplicating most of the fields from my business object. I am curious as to how any of the architecture gurus out there deal with this.

    Thanks,
    Matt

  • #2
    Two points;

    a - I always load objects in the request, so the "life" of an object is per request, and thus they never clash.
    b - if you are using hibernate (and OSIV), then unfortunately the only way I have found to handle this is to rollback the transaction if there are validation errors.

    HTH.

    Comment


    • #3
      Re:

      Originally posted by yatesco
      b - if you are using hibernate (and OSIV), then unfortunately the only way I have found to handle this is to rollback the transaction if there are validation errors.
      Interesting, I hadn't even thought about the reprocussions with hibernate yet. I'm sure I'll run into that too. I'll keep the rollback thought in mind though.

      I'm not so much worried about collision with other objects as I am just about the fundamental OO idea of an object never being in a bad state. I'm guessing allowing the objects to be in a bad state and having to do validation in a separate location is a compromise that prevents you from having to duplicate the work.

      -Matt

      Comment

      Working...
      X