I did try to populate first and then run the validation with the same result:
Type: BeanPopulator.PopulateBeanException Messages: Error populating bean allint.modules.aiadmin.models.userlevel with argument USERLEVELRATE of type class java.lang.String. Simple values are booleans, numbers, strings, and date-time values.
The value cannot be converted to a numeric because it is not a simple value.
The reason I am getting this particular error is that USERLEVELRATE is numeric but I pass a string in my form.
It appears the error is thrown before I even get to validation - at the populate() function that invokes the userlevel.CFC that has this for USERLEVELRATE constraints section:
userLevelRate = { required=true, requiredMessage=“Rate is required, Enter 0 for free.”, type=“numeric”,typeMessage=“Must Be a number with optional cents”}
So, the question is: how do I validate the model, if the error is thrown at populate, and before validation?
How do I validate rc/form scope with the built in validator? I only managed to find the validateModel() function so far. Bear with me, I am relearning even that little I knew in 2008 when I got out of the developer business.
I tried to do this: prc.validationResults = validateModel(target=rc, fields=“userLevelName, userLevelRate”, constraints=“userLevelForm”);
(tried allcaps just in case)
the config file has this in it in the shared section:
userLevelForm = {
userLevelName = {required=true, requiredMessage=“Name is required”, type=“string”},
userLevelRate = {required=true, requiredMessage=“Enter 0 if free”, type=“numeric”, typeMessage=“Numbers with decimals only”}
}
Everything seems to be in place, the constraints are registered, but the errors array is empty, although I enter a string in the USERLEVELRATE field which is numeric. The same happens if I leave the USERLEVELRATE empty, while it is required on constraints.
A followup - when the USERLEVELNAME field is submitted blank, the validator does work this one instance and populates the error array correctly. No validation is performed on the USERLEVELRATE still. Instead of dealing with the rc directly, I placed the two fields in a struct and tried to validate. Same result. Works only if the first field is empty and ignores the numeric one. Tried to change type from “numeric” to the ormtype “big_decimal” - same behaviour.