Validating data in ColdFusion 9: Part II
Earlier today I wrote an article on data validation in ColdFusion 9. Tonight I was working some more on my new project when I found another thing that kinda bugged me. As you probably already know you can declare a property and automatically have getters and setters created for them. This is really great except for when I need to validate what the user is entering.
In this example I have a user component with a bunch of different properties, one of which is date of birth. This is going to be a date so we want to make sure we declare this of type date. So far so good except when it comes time to collect data from the user. I know we would probably never do this but let's just say for this example we display a text box to the user and ask them to enter their date of birth. The real problem comes when we need to set the data. If the user enters anything other than a valid date you get the following error.
The value cannot be converted to a date because it is not a simple value.
I understand why its doing what it is doing but the real problem comes when you need to validate what the user is entering. No longer can we validate the data before its persisted we now need to validate it before it's set which really throws a wrinkle in to what I am trying accomplish. Anyone with some thoughts on this please share because I am kinda bummed out seeing this behavior. I know I can overwrite the setter but tends to be a pain in the butt and probably my only option for anything thats a non string.
