Print Page | Close Window

Validate sometimes null property

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3086
Printed Date: 02-Apr-2025 at 2:49am


Topic: Validate sometimes null property
Posted By: spudcud
Subject: Validate sometimes null property
Date Posted: 08-Nov-2011 at 5:22am

I have a date property that is nullable in the database but based on business logic may not be null in specific cases. To accomplish this I figured inheriting a class from PropertyValueVerifier would be the best way. The VerifyValue method is called when the date is changed to another date but does not get called when the date goes to null. Is this a bug or am I doing something wrong?

 
...
return new NullEndDateVerifier(
   typeof(StatusRqst),
   EntityPropertyNames.EndDateTimeDt,
   null,
   true);
...

      public class NullEndDateVerifier : PropertyValueVerifier
      {
         public NullEndDateVerifier(
            Type a_entityType,
            string a_sPropertyName,
            string a_sDisplayName = null,
            bool? a_bShouldTreatEmptyStringAsNull = null)
            : base(new PropertyValueVerifierArgs(a_entityType, a_sPropertyName, false, a_sDisplayName, a_bShouldTreatEmptyStringAsNull))
         { }

         public NullEndDateVerifier(PropertyValueVerifierArgs a_verifierArgs)
            : base(a_verifierArgs)
         { }

         protected override VerifierResult VerifyValue(object itemToVerify, object valueToVerify, TriggerContext triggerContext, VerifierContext verifierContext)
         {
            return new VerifierResult(true);
         }
      }

 
Thanks,
Steve



Replies:
Posted By: DenisK
Date Posted: 08-Nov-2011 at 7:33pm
Hi Steve;

You need to override the http://drc.ideablade.com/ApiDocumentation/IdeaBlade.Validation~IdeaBlade.Validation.PropertyValueVerifier~HandleNullPropertyValue.html - HandleNullPropertyValue method for nulls to be handled by the VerifyValue method.

// Can be overridden to return a custom null handling result or if null is returned,
// nulls will be handled by the VerifyValue method
protected override VerifierResult HandleNullPropertyValue(TriggerContext triggerContext, VerifierContext verifierContext) { 
    return null;
}


Posted By: spudcud
Date Posted: 09-Nov-2011 at 4:56am
Denis,
 
Works perfectly.
 
Thanks,
 
Steve



Print Page | Close Window