Skip to content

Commit

Permalink
Mixing messaging so custom constraints messages on properties in pare…
Browse files Browse the repository at this point in the history
…nt classes do not need to be duplicated for each inheriting class
  • Loading branch information
Lance Staples committed May 10, 2012
1 parent 886bdf7 commit ca1d744
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions system/core/Hyrule.cfc
Expand Up @@ -61,14 +61,15 @@ component accessors="true" {
private ValidationResult function validateAgainstRuleSet(required any target,required string context, required any ruleSet,required string stopOnFirstFail){
var result = new ValidationResult(new ValidationMessageProvider( getSettingsBean() ));
var meta = getMetaData(arguments.target);
var targetname = meta.Name;
var properties = {};

//build a map of properties by name for fast lookup later
do
{
for (var x = 1; x <=arraylen(meta.properties); x++)
for (var x = 1; x <=arraylen(meta.properties); x++){
properties[meta.properties[x].name] = meta.properties[x];
properties[meta.properties[x].name].className = meta.Name;
}
meta = structKeyExists(meta,"extends") ? meta.extends : {};
}
while(structKeyExists(meta,"properties"));
Expand All @@ -77,8 +78,6 @@ component accessors="true" {

// if this property already failed and we are stopping at first property failure skip this iteration
if(result.propertyHasError(validationRule.getPropertyName()) && arguments.stopOnFirstFail == 'property') continue;

var type = targetName & "." & validationRule.getPropertyName() & "." & validationRule.getConstraintName();

// if a context is requested and we do not find the property name in the context then skip this contstraint
if( arguments.context != "*"
Expand All @@ -102,7 +101,7 @@ component accessors="true" {
//make sure the constraint is set as an attribute on the property
//(validation messaging assumes all constraints exist there
properties[validationRule.getPropertyName()][validationRule.getConstraintName()] = validationRule.getConstraintValue();
result.addError(targetName,'property',properties[validationRule.getPropertyName()],validationRule.getConstraintName());
result.addError(properties[validationRule.getPropertyName()].className,'property',properties[validationRule.getPropertyName()],validationRule.getConstraintName());

//break out of the loop and stop validation if we are stopping on first object validation failure
if(arguments.stopOnFirstFail == 'object') break;
Expand Down

0 comments on commit ca1d744

Please sign in to comment.