Luis Majano Forums Notification: Post to Form Validation

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

Hi tszao,
One thing to be aware of is that if you are using Luis's method of
having the bean validate itself is that there may already an implicit validation
that takes place when the bean is populated.

Perhaps Luis can enlight us a
bit more on how the bean is populated internally by coldbox, for example if the
bean is populated by calling setter methods, unless these methods take their
argument as a type ANY, then the method call will fail if you try to pass a
value of the wrong type (i.e. pass a number to a date field)

Anyway, the
point I'm trying to reach is that you may still want to do a simple
pre-validation of values BEFORE populating the bean or saving the data or doing
whatever u need to do with the form data. This is because by doing this
pre-validation you can have control over the message that you can return to your
user. For example it is more user friendly to return a "Please select your age
from the drop-down box", than something like "Invalid argument type for
parameter data" or something like that.

PS: Please note that I'm referring
only to basic validation of data types and maybe empty values, and this should
not be used as a place to enforce business rules.

I'd like to
add a quick note on the sample validation code that Luis proposed (using a
validate method on a bean). Is important to realize that