[3.7.0 Railo] UDFValidator

I’m trying to understand how to use the UDFValidator. I have:

this.constraints = {
,“customthing”:{udf:this.vCustomThing}

}

And I have the corresponding vCustomThing(value,target):boolean function.

But when I validate, I get an error complaining that the validationData passed into the UDFValidator.validate() method is not a string. If I change to

this.constraints = {
,“customthing”:{udf:“this.vCustomThing”}

}

Then I get a different error. Is this a bug? Because the argument type for validationData is “string” in all of the interface definitions. Yet, UDFValidator calls arguments.validationData like it is a closure. So I’m confused as to how this could ever work.

Thanks.

Forgive me if the syntax is a little off, but either of the following should work:

UDF as closure:

this.constraints = {
‘fieldabc’ = {
udf = function(value,target) {
if(arguments.value eq 0) {
return false;
}
return true;
},
udfMessage = ‘UDF validation failed.’
}
};

Method instead of UDF:

And more specifically, the closure version will only work if you’re on CF10.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

I’m on Railo 4.1, I assume the closure should work there too. But it does not. I don’t see how it could, considering the argument validationData is typed as “string” in the IValidationManager and IValidator interfaces.

Since I am passing in a closure or function as the value for validationData, it throws an exception.

Sorry, I confused your thread for someone else’s who said they were on 9.02. Have you changed the “string” to “any” to see if it works. The validation could have been added later in error. I haven’t had a chance to look at that code myself though. I was hoping Luis would chime in.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

I started down the path of changing “string” to “any” in my validator, but this causes another error in that my validator no longer matches the interface. So, then I changed it to “any” in both the iValidationManager and iValidator interfaces, and subsequently broke all of the other core validators, because they still use “string” and no longer match the interface definition.

I thought about changing them all to “any” but at that point it seemed like kind of a rabbit hole and not knowing enough about why Luis decided on using “string” instead of “any” to begin with I was worried about other unintended consequences.

updated and committed

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano