Validate
Overview
New validation approach by creating and reusing Attribute Validations per Entity. By combining individual Attribute Validations into ValidationProcesses you create all your application validations in a structured, flexible and reusable way.
Documentation
Validate: a structured, reusable approach to validations in Mendix
The Validate module provides a non-persistent Validation entity that is to be associated with each entity that is to be validated.Storing validations on an object into associated non-persistent Validation objects gives you flexibility to handle and show validations in the way you choose.
The approach is to break validations down to Attribute level per Entity. By creating Attribute Validation microflows for each Entity, you’ll get a clear overview of all validations in your application.By combining individual Attribute Validations into static or dynamic ValidationProcesses you create all your application validations in a structured, flexible and reusable way.ValidationProcesses are used in pages (eg. Save), in create/update microflows (eg. imports) or just in jobs to check the data quality of your application regularly.It is recommended to store all Entity_Attribute validations and static ValidationProcesses of a module in a Validations folder with subfolders per Entity. Like this maintaining and reusing validations of a module will be clear and easy.
Dependencies:
Created with Mendix 9.6.4 (now maintained in Mendix 9.18.4 for convenience)
Depends on CommunityCommons module for dynamically starting microflows for dynamic ValidationProcesses
Depends on TaskQueueScheduler to schedule validations in batch (on taskqueue)
So please install that first when you do not have it installed already.
How to configure:
Simply download Validate module package into your application
*** Upgrading to version 2.0.0 ***
All code from previous versions is still there so after upgrading to version 2.0.0 all should still work.
How to use:
Simply start creating your attibute and process validation microflows per entity following the new version 2.0.0 microflow templates (see attached screenshots or check the validations created for AttributeValdiation/ValidationProcess). Use standard ValidationFeedback to raise validation messages.Please be aware that following the microflow templates is essential for the approach to work!
Per entity create SAVE microflow that calls the validate process to validate the entity object before actual commit.
At calling the validate process set NoFeedback to
false: when you want validation feedback shown on your pages
true: when no validation feedback is desired
On Save: call this SAVE microflow!
It is recommended to store all validations of a module in a Validations folder with subfolder per entity. Like this maintaining and reusing validations will be clear and easy.
Each Validations\ subfolder holds:
- Attribute validation microflow(s) per validated attribute
- Entity ValidationProcess microflow(s) per entity process
RUN validations:
Validate module allows you to run your created validations independently.
A great way to check the quality of your data!
Validations can be started manually from the ValidationProcess_Overview page.
Even better:
Fom ValidationProcess_Edit page you can schedule ValidationProcesses to run automatically at specified intervals (with TaskQueueScheduler module installed), so you can monitor the quality of your data constantly.
All it takes to achieve this to create following microflows for each EntityType to validate:
Sub_RUNAttributeValidation_to execute given AttributeValidation validation on all relevant EntityType objects
Sub_RUNValidationProcess_ to execute given ValidationProcess validations on all relevant EntityType objects
Sub_ValidationResult_Open_ to open involved EntityType object from ValidationResult list
To create these microflows you best copy existing microflows and adjust those to the new EntityTypeFor performance it is advised to consider changed objects only and not all objects all the time.
Once you have created the microflows you can hit link on theValidationProcess_Overview page to have all entity validations available on the page.
Using dynamic ValidationProcesses:
A dynamic ValidationProcess is not for a specific Entity type; it is just a collection of AttributeValidations.
On ValidationProcess_Overview page create a ValidationProcess with EntityValidationProcess=No
Then all attribute validations to the dynamic validation process.
When created you can run the dynamic ValidationProcess manually or schedule it when needed
Validation Microflow Templates
Attribute Validations
An attribute validation microflow must be named as Val_EntityName_AttibuteName_Description (short free text) Or for association Val_EntityName_Associated EntityName (or part)_Description (short free text)
An attribute validation microflow needs the object to be validated as input. With that it does the actual checking. When checking finds an irregularity please use the standard Mendix ‘Show validation message’ action to raise a validation message with the attribute on page. For an attribute only one validation message can be shown, but you can combine multiple irregularities in one validation message.
A validation microflow must return the validation message or empty string in case all is fine.An attribute validation microflow should look like the sample attribute validation screenshot.
Validation Processes
A validation process microflow must be named as Val_Process_EntityName_Description (short free text).
A validation process microflow needs the object to be validated and a boolean ‘NoFeedback’ as input. When Boolean ‘NoFeedback’=true the system will not show the validation messages on page.
A validation process microflow calls all relevant attribute validation microflows for the input entity object and returns a string with all resulting ValidationMessages (concatenated with ‘|’) by calling Java module ‘get feedback validations’.
An entity validation process microflow should look like the sample validation process screenshot.
Many entity types have just 1 validation process, but please be aware there can be more than 1 validation process microflow per entity type as actions (like New, Edit or Delete) can require different validations. No problem, just set Description in name so that is clear when the validation process relevant. All validation processes should call a subset of entity attribute validations; attribute validations can be reused in various validation processes.
SAVE microflows
On custom Save (also eg. Add or Delete) entity action of the entity object the relevant entity process validation microflow is called and the resulting validations are checked. On validations raised the validation messages are shown on page when the validation process is called with ‘NoFeedback’=false. After calling the validation process the Save process must check the validations string if any irregularities were found. With irregularities the Save process must stop. Only when no validation is raised the changes are committed to the entity object.
An entity action with validations should look like the sample save microflow screenshot.