Validating a type with multiple member of same complex type

Topics: Validation Application Block
Nov 25, 2008 at 3:14 PM
Dear All,
We have a requirement to integrate object validation with the UI controls that are bound to object properties. We use ValidationProvider to associate each control with the member of the type. The challenge is that if the object has multiple members with the same type, there is no way to identify the member associated with the type on which validation error has occurred.
Let me explain with an example.
Customer type has 2 members namely CorrespondenceAddress and ResidentialAddress each of type Address.
If wrong data is entered in the UI fields for both Address types, there is no way to uniquely identify which address instance (CorrespondenceAddress or ResidentialAddress) the error has occurred in. ValidationResult.Target is not of much help.

Is there any way to resolve this ?

Thanks in advance...
Nov 26, 2008 at 5:54 AM
Edited Nov 26, 2008 at 6:41 AM
Why not put the name of the property in the Tag property of the Validator?  This will reflect in the ValidationResult.Tag property.

[

NotNullValidator(Tag = "CorrespondenceAddress ")]
public Address CorrespondenceAddress
{
    
get;
    
set;
}

 

[

NotNullValidator(Tag = "ResidentialAddress")]
public Address ResidentialAddress
{
    
get;
    
set;
}

 




Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Nov 26, 2008 at 2:41 PM

Hello Sarah,
Thanks for the response.
As per my understanding, assigning Tag property on the complex type member has no meaning.
Please note, in the example used in my initial post, both CorrespondenceAddress and ResidentialAddress complex properties are being validated using ObjectValidator. Each member of address type is getting validated using other validators like StringLengthValidator and NotNullValiadator. As per my observation, the ValidationResults object always carries the entries for validation failures for each simple property like Line1, Line2, State and Country (members of Address complex type) if validators exist for these members.
Our requirement is that tf Line1 of the CorrespondenceAddress property (which is of type Address) is not specified or carries incorrect value, then ValidationResult should flag the error at CorrespondenceAddress.Line1 property rather than saying Line1 of Address type is incorrect.

I hope I am able to communicate my problem properly.

thanks...

Nov 27, 2008 at 1:45 AM
Does obtaining the actual value which did not pass the validation not an option for you? If not, I think you may have to implement your own mechanism of traversing the properties as I don't think there is built-in support for this in EntLib.  See these threads,
http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=13558
http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=31009



Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com