3. Validator.cfc - New validator types implemented: @custom, @customList, @bean and @beanList.
public ValidationResult function validate(required any dto,Struct dtoMD,ValidationResult vr,String context="*"){
...
case "CUSTOM" : {
try {
validator = createObject("component","#prop.custom#");
if( !validator.isValid(prop, arguments.context, arguments.dto) ) {
addErrorMessage(componentName=dtoMetaData.name, property=prop, validationResult=validationResult, validationType=custom);
}
} catch(any e) {
throw(type="ValidatorError", message="Custom validation component #prop.custom# not found");
}
break;
}
case "CUSTOMLIST" : {
for (var custom in listToArray(prop.customList)) {
try {
validator = createObject("component","#custom#");
if( !validator.isValid(prop, arguments.context, arguments.dto) ) {
addErrorMessage(componentName=dtoMetaData.name, property=prop, validationResult=validationResult, validationType=custom);
}
} catch(any e) {
throw(type="ValidatorError", message="Custom validation component #custom# not found");
}
}
break;
}
case "BEAN" : {
if (isNull(getBeanFactory())) {
throw(type="ValidatorError", message="Bean Factory is not injected in Validator");
}
validator = getBeanFactory().getBean(prop.bean);
break;
}
case "BEANLIST" : {
if (isNull(getBeanFactory())) {
throw(type="ValidatorError", message="Bean Factory is not injected in Validator");
}
for (var beanName in listToArray(prop.beanList)) {
validator = getBeanFactory().getBean(beanName);
if( !validator.isValid(prop, arguments.context, arguments.dto) ) {
addErrorMessage(componentName=dtoMetaData.name, property=prop, validationResult=validationResult, validationType=beanName);
}
}
break;
}