Skip to main content

Validation Contexts

  • 3 minutes to read

Validation Rules can be checked in the following Validation Contexts.

Standard Contexts:

  • Action

    XAF allows the use of Actions as Contexts. In this instance, a Rule is checked when a specified Action is executed. To associate a context identifier with a particular Action, set it for the ValidationContexts property of the Application Model‘s ActionDesign | Actions | <Action> node. You can associate any number of context identifiers with an Action. To do this, specify the identifiers as a list separated by semicolons.

  • Save

    If you specify the DefaultContexts.Save Context for a Rule, this Rule will be checked each time the required object (or its properties) is saved to a database. Additionally, in-place validation (see IModelValidationContext.AllowInplaceValidation) is enabled for this Context (the default setting). To specify the Save Context in the Model Editor, set the IRuleBaseProperties.TargetContextIDs property to Save.

  • Delete

    With the DefaultContexts.Delete Context, a Rule is checked when a specific object is deleted. To specify the Delete Context in the Model Editor, set the IRuleBaseProperties.TargetContextIDs property to Delete.

Custom Contexts:

  • If the standard Contexts do not satisfy your requirements, you can implement custom Contexts. For details, refer to the Implement Custom Contexts topic.

In addition to a Context, you can specify additional contextual criteria for a Rule. In this instance, the Rule will be checked only if the property values of the validated object (or property) satisfy the specified criteria. For instance, the RuleRequiredField rule can be checked for the AssignedTo property if the Status property is set to Active. To learn how to set this criteria, refer to the required Validation Rule attribute’s TargetCriteria property description.

Important

As the Validation system is designed to control user input, the system works automatically only for Views and Object Spaces assigned to these Views. As such, if you manually instantiate a BaseObjectSpace and perform object modifications through this Object Space, these modifications are not validated. However, if you need to validate such modifications, you can use the IRuleSet.Validate method of the IRuleSet object. For a detailed explanation, refer to the following help topic: Implement Custom Contexts.

The Validation Module supplies the ShowAllContexts Action (which has the Validate caption in the UI). This Action is activated for editable Detail Views and allows end users to check predefined rules when editing data. When the ShowAllContexts Action is executed, all Validation Rules that are specified for the current object are checked in all associated contexts. The Validation results are ContextValidationResult class instances. A pop-up window containing the ContextValidationResult List View is invoked if any broken Validation Rule is detected. All broken rules are detailed in this List View. To view more details on the validation results, double-click a grid item. The ContextValidationResult Detail View will be invoked.

Validation_ContextValidationResult_Win

Validation_ContextValidationResult_Web

The ContextValidationResult Detail View displays the DisplayableValidationResultItems collection. Each broken Validation Rule can be displayed via the DisplayableValidationResultItem Detail View, providing more details on validation results. This Detail View can be invoked by double-clicking a collection item.

Note that rules may have one of the following states: