Validation

Posts   
 
    
scottsimms
User
Posts: 12
Joined: 13-Feb-2007
# Posted on: 16-Feb-2007 05:08:39   

Hi,

I am using Adapter method and I am implementing a generic validation class that decends from ValidatorBase. This generic validator will take care of Nulls and Range Checking at an Entity level. I have found though that when a field value is set, the following method in EntityBase2 is called :

private bool ValidateValue(IEntityField2 fieldToValidate, object value, int fieldIndex)

This method does it's own range checking and effectively overrides my validator. Is there any way to override this behavior and leave all Field and/or Entity validation to an 'external' validation class?

Thanks,

Scott.

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 16-Feb-2007 08:53:47   

You should implement/override ValidateFieldValue in the custom validator class Example:

// C# in validator class deriving from ValidatorBase.
protected override bool ValidateFieldValue( IEntityCore involvedEntity, int fieldIndex, object value )
{
    bool toReturn = true;
    switch((OrderFieldIndex)fieldIndex)
    {
        case OrderFieldIndex.OrderId:
            // id is valid if the value is > 0
            toReturn = ((int)value > 0);
            break;
        default:
            toReturn = true;
            break;
    }
    return toReturn;
}

scottsimms
User
Posts: 12
Joined: 13-Feb-2007
# Posted on: 16-Feb-2007 09:12:10   

OK, tried that, but it appears that 'ValidateFieldValue' on ValidatorBase is called after the range validation inside the 'ValidateValue' method, and so if a field is out of range, e.g too many chars, an exception is raised and the custom validation inside ValidatorBase will not be called.

I must be missing something here...

Thanks,

Scott.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 16-Feb-2007 09:17:51   

That's indeed the current behavior, as the internal value set code validates the value if it will ever be possible to store that value in the field without errors. A range violation makes the value not storable.

For v2.1, a switch is planned so you can switch this off, as in: you can make the validator be called before the internal validation.

Frans Bouma | Lead developer LLBLGen Pro