Custom Validation Question

Posts   
 
    
JoeyM
User
Posts: 15
Joined: 07-Aug-2012
# Posted on: 07-Aug-2012 16:17:22   

Hello,

I am a bit new to LLBLgen, figured out almost everything now, there is just one thing i can not easily find.

I created my own Validator classes and use policy injection. Works nice but... I also want to use the default LLBL gen generated field validations. I am a bit lazy and don't feel much like to program all the "database level" default field validations my self (length validations, not null validations etc).

I can not imagine that there is a good way to re-use this generated code?

Can somebody please provide me a clear example how to do this ?

Thanks in advantage, Regards, Joey

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 07-Aug-2012 16:20:19   

The field validation (length etc.) is done before your custom validation, it's not clear to me whether you want to simply redo that validation again in your custom validation classes (dunno why though wink ) or you want to replace that validation with your own which e.g. validates differently?

Frans Bouma | Lead developer LLBLGen Pro
JoeyM
User
Posts: 15
Joined: 07-Aug-2012
# Posted on: 07-Aug-2012 16:39:47   

Hi Otis,

I already found the problem -> in my app config i put the key on value 2 ;-) but it should be 0 and now both my validations are working, perfect!

<add key="buildInValidationBypassMode" value="0"/>

Thanks simple_smile

Regards, Joey

JoeyM
User
Posts: 15
Joined: 07-Aug-2012
# Posted on: 07-Aug-2012 19:16:42   

Otis wrote:

The field validation (length etc.) is done before your custom validation, it's not clear to me whether you want to simply redo that validation again in your custom validation classes (dunno why though wink ) or you want to replace that validation with your own which e.g. validates differently?

Hello Otis,

One Question. What if the user is in a textbox, and click's the save button. In the given validation example, i don't see how that fires the default entity validation?

Can you give me some insights on that one?

Thanks in advantage,

Regards, Joey

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 07-Aug-2012 21:39:31   

If the TextBox is bound to one of the entity's fields, then when the user changes the value of the TextBox, and it loses focus, the field gets the new value, and that's when the built in validation is used, to validate the value just before setting the field.

JoeyM
User
Posts: 15
Joined: 07-Aug-2012
# Posted on: 08-Aug-2012 08:40:16   

Walaa wrote:

If the TextBox is bound to one of the entity's fields, then when the user changes the value of the TextBox, and it loses focus, the field gets the new value, and that's when the built in validation is used, to validate the value just before setting the field.

Maybe my explanation was not really good, sorry for that simple_smile

If the user creates a new entity and his cursor never reached certain fields (skipped) and just hits the save button. then i need to check if my entity has all the required fields filled in (let's say is valid to get the entity into the database). Like i see it now, databinding and validation doesn't work if the user doesn't use the field, right?. And i don't feel much for programming this in a custom error provider every time in the GUI.

So, is the custom validation layer the place where i need to program those checks (before save, validate entity etc)? If yes, i think it should be nice if there was a method on an entity that can be called and fires the default (in house) database validations (not null, lengths etc). Also it appears to me that i can not customize the error validation messages that ships with the generated code, my endusers like friendly messages. (maybe multilangual)

I hope i missed some things! Joey.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-Aug-2012 20:26:05   

The built-in validation is to ensure fields are not set with invalid data. And it is only triggered when a field is set. This should not be mistaken with Entity Validation.

Also built-in validation is mainly used ot notify the developer and /or tester of a potential issue.

If you want to have something to be displayed to the user, you should write your own validator class.

Also in your case, what you need is Entity Validation, becuase it's triggered with a specific action on the entity (Save action).

For entityValidations, you should write your own Validator Class.

JoeyM
User
Posts: 15
Joined: 07-Aug-2012
# Posted on: 08-Aug-2012 21:04:34   

Walaa wrote:

The built-in validation is to ensure fields are not set with invalid data. And it is only triggered when a field is set. This should not be mistaken with Entity Validation.

Also built-in validation is mainly used ot notify the developer and /or tester of a potential issue.

If you want to have something to be displayed to the user, you should write your own validator class.

Also in your case, what you need is Entity Validation, becuase it's triggered with a specific action on the entity (Save action).

For entityValidations, you should write your own Validator Class.

Hello Walaa,

I already thought that would be the case... just wanted to be sure i wasn't missing anything. There is a great opportunity here for LLBLgen (i think). It would be nice if this checks (invalid data) would also be available in the custom validator classes.

But no sweat, i know what to do now. Thanks for taking time to answer my questions.

Regards, Joey

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-Aug-2012 21:08:15   

If you use your own custom validator, you still have the option to disable the built in validation, or by-pass it, or only b-pass it if a validator is used. But still this would be used for field validation, not for entity validation.

Good luck.