New Posts New Posts RSS Feed: Custom validation
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Custom validation

 Post Reply Post Reply
Author
giotis View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Apr-2012
Location: Greece
Posts: 53
Post Options Post Options   Quote giotis Quote  Post ReplyReply Direct Link To This Post Topic: Custom validation
    Posted: 01-May-2012 at 2:22am
Dear friends ,
exploring the ValidationErrorMessageProcessor I noticed that only inform the user about the error field and not the
named entity in ValidationErrorsView and I decided to include this information but I found two things,

1. when we add our own custom validations not updated the {Verifier.ApplicableType}
    which keeps the information of the entity

2. Since fields they have RequiredAttribute why require extra custom validation?

    namespace DomainModel {
        [DataContract(IsReference = true)]
        public class Address : AuditEntityBase, IHasRoot    {
             internal Address()        {   }
             ...
             /// <summary>Gets or sets the StateId. </summary>
             [DataMember]
             [Required]
             public Guid StateId { get; set; }
 
              /// <summary>Gets or sets the State. </summary>
              [DataMember]
              [Required]
              public State State { get; set; }
              ...
              public override void Validate(VerifierResultCollection validationErrors)   {
                     if (State.EntityFacts.EntityAspect.IsNullOrPendingEntity)
                          validationErrors.Add(new VerifierResult(VerifierResultCode.Error, "The State field is required", "State"));
              }
     }

best regards
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 01-May-2012 at 9:17am
Can you provide some more information on your first issue?
 
On your second point. Custom validation is needed here, because StateId and State will always have a value assigned. If you don't explicitly set StateId it will be initialized with Guid.Empty() and State will be initialized with the null entity not the null value. The RequiredAttribute is a .NET attribute that doesn't understand the null entity. It looks for a null value. So, the two options are doing what I'm doing or put a DevForce Verifier on the State property, which understands the null entity.
 
One of the key features in DevForce is that navigation properties are never null, to avoid NullReferenceExceptions when binding to the UI. You can learn more about this topic here:
 
Back to Top
giotis View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Apr-2012
Location: Greece
Posts: 53
Post Options Post Options   Quote giotis Quote  Post ReplyReply Direct Link To This Post Posted: 01-May-2012 at 4:11pm
When we add a new StaffingResource and after save without fill appropriate Address fields then raise an exception
if we put a breakpoint in ValidationErrorHandler the validationErrors return a VerifierResult collection
So we see that custom Verifier type is null

                            [DataContract]
                            [DebuggerDisplay("{ResultCode}; {Message}; {Verifier.ApplicableType}")]
                            public class VerifierResult   {

validationErrors = { [0] ...
                                [1] = Error; "The Address1 field is required."; {DomainModel.Address}
                                ...
                                [5] = Error; "The State field is required"; null
                                ...
                               }

namespace Common.Validation{
    public class ValidationErrorHandler : IValidationErrorNotification    {
        public void OnValidationError(VerifierResultCollection validationErrors)        {
            if (validationErrors.HasErrors)
                EventFns.Publish(new ValidationErrorMessage(validationErrors));
        }
    }
}
Back to Top
giotis View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Apr-2012
Location: Greece
Posts: 53
Post Options Post Options   Quote giotis Quote  Post ReplyReply Direct Link To This Post Posted: 01-May-2012 at 4:19pm
How to inform the user about the name of entity of field
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 01-May-2012 at 4:35pm
Unfortunatley, the VerifierResult class doesn't have a constructor that takes the TargetInstance or a public setter for the TargetInstance property. The setter is internal, so there's currently no way to specify the entity. I suggest you post a feature request to the Data Verification forum.
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down