Validation Best Practices

Posts   
 
    
Posts: 33
Joined: 05-Feb-2005
# Posted on: 05-Feb-2005 19:32:53   

Hey guys,

I've just started using LLBLGen Pro (actually I'm new to .NET too) and I am wondering how to best use the validation classes in LLBL in the presentation layer of a web app. At first glance, the per field validation looks like it should throw an exception at the first error it finds. What then is the best way to construct a validation summary for the user, notifying him of ALL the problems with the data he entered? Also are there any tools to help validate information on the client, or does all the validation have to take place on the server?

thanks,

Jason

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 05-Feb-2005 22:01:48   

field validation is placed in the validation classes, entity validation is placed in IEntityValidator implementations you add to the entity. Field validators are triggered when you set the value, IEntityValidator instances are triggered when Validate is called (usually before save). If you want to report an error for all fields at once, I'd go for the IEntityValidator implementation, do a check for all the fields, create a custom error message and throw that back with an ORMEntityValidationException, which is easily to catch in your own code so you can handle it directly by producing error displaying code.

Frans Bouma | Lead developer LLBLGen Pro
Malcolm
User
Posts: 1
Joined: 19-Jan-2006
# Posted on: 19-Jan-2006 18:50:47   

If you are using .NET 2.0 you can use the new Data (dictionary) property of the base Exception class to return a list of objects that contain the info about ALL the validation errors that occurred. You have to make sure the objects you put in this collection are serializable.