BuildInValidationBypassMode

Posts   
 
    
Liz
User
Posts: 3
Joined: 17-Feb-2009
# Posted on: 17-Feb-2009 16:15:27   

LLBLGen Pro. Version: 2.6 Final (October 6th, 200sunglasses

I am new to LLBLGEN so excuse me if my terminology is not correct. I would like to run the built-it validation on demand. So I turn off the built in validation mode by

BuildInValidationBypassMode = BuildInValidationBypass.AlwaysBypass;

I would then like to run it before I save. However, I can't find the name of the function to do that. I would prefer to use the built-in validation instead of recreating it. Plus, I would like to add more to it. I don't want the data to be wiped out as they're entering the data when the data is inValid. Our design specification calls for this to happen at the end on save. Is there such a function? Thanks!

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 17-Feb-2009 21:32:56   

The method you want is called OnValidateEntityBeforeSave. There are several ways to supply code for this function - they are detailed in the documentation. Please have a read through and then feel free to get back to us with any specific questions.

Thanks

Matt

Liz
User
Posts: 3
Joined: 17-Feb-2009
# Posted on: 17-Feb-2009 23:11:53   

Thank you for the pointer in the documentation. I have the following entity methods (not validation methods):

    **protected override void OnValidateEntityBeforeSave()**        
   {
        base.ValidateFields();
    }

**  public void ValidateFields()**      
   {
        foreach (Object field in this.Fields)
        {
            int fieldIndex = this.Fields.IndexOf(field);

            if (field.GetType() == typeof(EntityField2))
            {
                isValid &= this.ValidateFieldValue(fieldIndex, 
                                                   ((EntityField2) field).CurrentValue);
            }
        }

        if (!isValid)
        {
            this.SetEntityError("Please correct the indicated fields.\n");
        }

    }

**protected override bool ValidateFieldValue(int fieldIndex, object value)**    
   {
        bool isValidField = true;
        string eMsg;

        switch ((LeadFieldIndex)fieldIndex)
        {
            case LeadFieldIndex.EmailAddress:
            {
                if (((string) value != String.Empty) &&
                    ((string) value != null))
                {
                    Regex normal = new Regex(RegexPatternConst.EMAIL_NORMAL);
                    isValidField = normal.IsMatch((string) value);


                    if (isValidField == false)
                    {
                        eMsg = "Must be in the form xxxxx@xxxx.xxx";
                        this.SetEntityFieldError("EmailAddress",
                                                 eMsg,
                                                 false); 
                    }
                    else
                    {
                        this.SetEntityFieldError("EmailAddress",
                                                 String.Empty, false);
                    }
                }

                break;
            }
            default:
                isValidField = base.OnValidateFieldValue(fieldIndex, value);
                break;
        }
        return isValidField;
    }

At what point is the built-in validation occuring and how do I now it has executed? How do I catch events generated by the built-in validation? How do I know what error it generated? confused

Liz
User
Posts: 3
Joined: 17-Feb-2009
# Posted on: 17-Feb-2009 23:25:57   

And how do I then prevent the save from occurring based on the outcome?

Thanks!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Feb-2009 04:06:15   

Hi Liz,

The problem is that the built-in validation logic is called when you "set a field value". When you save the entity it's too late for that. The method used to do this built-in validation is private (EntityBase2.ValidateValue) so you can call it directly.

At his point, you have to decide between these options:

A. Active the built-in validation always. B. Disable the built-in validation and manage that kind of validation by yourself (you can look at source code if you want a hint of that).

David Elizondo | LLBLGen Support Team