Luis Majano Forums Notification: Post to Form Validation

Title: RE: Form Validation
Thread: Form Validation
Forum: Need Help?
Conference: ColdBox
User: oscararevalo

I see what you are saying about the memento pattern, and seems that is similar
to the first alternative I was talking about, but what I don't understand is why
would you still need to keep the "validate()" method on the bean, if you are
already validating the both ways in which the bean can be populated: the
implicit type-checking validation on the setters and the more open-ended
validation on the setMemento. Also, how do you see a "First name cannot be
empty" message traveling from the setMemento method to the user? by throwing an
error?

About the separate validator object, I was not thinking about it as
necessarily being part of your domain model, but more of a helper that can
bridge the gap between your presentation and your model. The validator object is
not that concerned with having actual valid objects, since that is implicitly
done by the setters; it is more concerned with translating what comes from the
client into what the bean is expecting, and handling grafefully any mismatches,
all this done in a manner that is decoupled of how the user-interface is
implemented.

The idea of the validate() method assumes that for some reason
you may end up with incorrect data inside your bean, which shouldn't be the
case, since that is the original purpose of having your data encapsulated as a
bean in the first place. Instead what you really want is to make sure that your
event handlers populate the bean correctly, and that is why this validator
object is a separate entity; because from the bean's point of view the
functionality of validating the data coming in is redundant and unnecessary.
PS: increase your session time-out. I keep getting errors.

http://www.luismajano.com/forums/index.cfm?event=ehMessages.dspMessages&threadid=099E0187-123F-6116-421FA3B9B2F4006A