Need a Help on Validators

Topics: Validation Application Block
Jul 30, 2009 at 1:45 PM

Hi,

Im very New Validators. Im having doubt on using EL VAB based validators.Suppose Im having Domain Object with Property Named AS Description.

 

        [ValidatorComposition(Microsoft.Practices.EnterpriseLibrary.Validation.CompositionType.Or)]
        [NotNullValidator(MessageTemplateResourceName = INF.Shared.Constants.MessageTemplateResourceName.MandatoryField,
                       MessageTemplateResourceType = typeof(SystemMessageTemplate),
                        ]
        [StringLengthValidator(1, RangeBoundaryType.Inclusive,
                            500, RangeBoundaryType.Inclusive,
                            MessageTemplateResourceName = INF.Shared.Constants.MessageTemplateResourceName.InvalidStringLength,
                            MessageTemplateResourceType = typeof(SystemMessageTemplate),
                             ]
        public string Description
        {
            get
            {
                return _description;
            }
            set
            {
                 _description = value;
                OnNotifyPropertyChanged();
            }
        }
Well 2 validation messages are shown on the screen,when the value of description is set to NULL.According to me Only NULL validator has to be executed not the String Length Validator since im adding CompositionType.OR.
According to it only one validation has to be fired(Is my understanding correct related composite validators like OR)

Is there any possiblity of firing only null validator not the string length validator when there is NULL Value in applied in Setter property 

With regards,
Mahens

 


 

 

 

[ValidatorComposition(Microsoft.Practices.EnterpriseLibrary.Validation.CompositionType.Or)]
        [NotNullValidator(MessageTemplateResourceName = INF.Shared.Constants.MessageTemplateResourceName.MandatoryField,
                       MessageTemplateResourceType = typeof(INF.Shared.Resources.SystemMessageTemplate),
                       Ruleset = INF.Shared.Constants.RuleSetName.InsertUpdate)]
        [StringLengthValidator(1, RangeBoundaryType.Inclusive,
                            500, RangeBoundaryType.Inclusive,
                            MessageTemplateResourceName = INF.Shared.Constants.MessageTemplateResourceName.InvalidStringLength,
                            MessageTemplateResourceType = typeof(INF.Shared.Resources.SystemMessageTemplate),
                            Ruleset = INF.Shared.Constants.RuleSetName.InsertUpdate)]
        public string Description
        {
            get
            {
                return _description;
            }
            set
            {
                if (value == string.Empty)
                {
                    _description = null;
                }
                else
                    _description = value;
                OnNotifyPropertyChanged();
            }
        }

 

 

 

 

 

Jul 31, 2009 at 2:31 AM

Where did you get the 2 validation messages?  In the 4.1 version, you will only get one validation message, the default message of the OrCompositeValidator which is:

"All validators failed for key \"{propertyName}\"."

unless you override it.  The 2 validation messages can be found in the NestedValidationResults property of the ValidationResult object containing the error message generated by the OrCompositeValidator. 

If you are using the 4.1 version, you are probably looping the NestedValidationResults property.

 

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