A developer asks:
We have a form with two input properties, Card Number and Authorization Code. I planned to reference edit validation rules (Rule-Edit-Validate rule type) in those properties to ensure that the minimum length requirements are met (12 and 6 characters respectively).
However, Guardrail #9 states "Whenever the value of a property is calculated or validated, use declarative rules whenever appropriate". Yet in my Fast Track class, I recall advice to avoid Constraint rules for user input validation.
Which approach is better in this case? The Rule-Edit-Validate approach seems to make more sense because the constraint rules involve the value of the property rather than a descriptive attribute such as length.
Constraints rules (Rule-Declare-Constraints rule type) are attractive because you can control more of what you compare, and you can create a better user interface. No Java skills are required.
But depending upon how you define the Constraints rule, the system may execute the rule either every time the property is referenced or every time it changes. Such checking could impact system performance.
The recommended approach depends on how frequently the property value is presented and accessed.
- Use Constraints rules unless there will be an impact on system performance.
- Use Rule-Edit-Validate rules if your application doesn't require multiple, different validations for the data values, and if the Constraints approach could affect system performance