Print Page | Close Window

How to override default verifiers offered by Devforce

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1586
Printed Date: 24-Apr-2024 at 2:24am


Topic: How to override default verifiers offered by Devforce
Posted By: pchavan2009
Subject: How to override default verifiers offered by Devforce
Date Posted: 15-Dec-2009 at 3:04am

In my Employee Class, property EmpName cannot be blank.

In the ServerModelDesigner, the StringLengthVerifier is added with IsRequired set to true, due to which the devforce's default validation message "EmpName is required" gets displayed when we call the VerifierEngine.Execute(...) function.
 
We have partial class of Employee where we create verifiers related to Employee.
We need to override the StringLengthVerifier created in the ServerModelDesigner and show our custom message as to "Employee Name is required" instead of "EmpName is required".
 
So when we call the VerifierEngine.Execute(...)  function, it should return only one VerifierResult "Employee Name is required"
 
Can any one please respond with a solution?



Replies:
Posted By: GregD
Date Posted: 17-Dec-2009 at 4:51pm

pchavan:

You can set up a PropertyNameToDisplayNameTranslator delegate to make verifiers use the display name instead of the property name in their messages, as follows:

_entityManager.VerifierEngine.PropertyNameToDisplayNameTranslator =

  delegate(Type pType, String pPropertyName) {

    var attr = ReflectionFns.GetAttribute<DisplayAttribute>(pType.GetProperty(pPropertyName));

return attr.Name;

};

 
Then just set the Display Names for your properties, as desired, in the Object Mapper -- e.g., set the Display Name for the EmpName property to "Employee Name" -- and the verifier will use that name in the message.
 
 
 
 


Posted By: pchavan2009
Date Posted: 17-Dec-2009 at 9:42pm
Thanks a lot! it worked



Print Page | Close Window