ColdFusion 9 is brining some awesome new features and right near the top for me are implicit getters / setters. Writing these can be tedious and straight up boring but soon enough that will be a thing of the past. On top of that they have adding some validation features to these properties. Two new attributes have been added to the property tag, validate and validateparams. Rupesh Kumar has a great write up on this over on his blog but here is the short version.
Possible values of validate are.
- string
- boolean
- integer
- numeric
- date
- time
- creditcard: A 13-16 digit number conforming to the mod10 algorithm.
- email: A valid e-mail address.
- eurodate: A date-time value. Any date part must be in the format dd/mm/yy. The format can use /, -, or . characters as delimiters.
- regex: Matches input against pattern specified in validateparams.
- ssn: A U.S. social security number.
- telephone: A standard U.S. telephone number.
- UUID: A Home Universally Unique Identifier, formatted 'XXXXXXXX-XXXX-XXXX-XXXXXXXXXXXXXXX', where 'X' is a hexadecimal number.
- guid: A Universally Unique Identifier of the form "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" where 'X' is a hexadecimal number
- zipcode: U.S., 5- or 9-digit format ZIP codes
- min: Minimum value if 'validate' is integer/numeric
- max: Maximum value if the 'validate' is integer/numeric
- minLength: Minimum length of the string if the 'validate' is string
- maxLength: Maximum length of the string if the 'validate' is string
- pattern: regex expression if the validator specified in 'validate' attribute is regex
This is a quick example of a user component using some of the new validation.
This seemed like exactly what I wanted, an easy way to validate data. A closer look at how it actually works though left me wanting more. This will do exactly what it says and validate the data but this is how it's done. To show how this works we will create an instance of our user component and try to set our first name property The requirement for our first name was that it should be at least 2 characters long. I was thinking that it would somehow trap these errors but instead when I ran the example I saw the following error on screen.
The length of the string, 1 character(s), must be greater than or equal to 2 character(s).While this is nice I don't really think I could use in a real application because its not a nice way of informing the user of what went wrong. This was the base of a new project I have been working on that I hope to share with you soon.

#1 by Brian Carr on 9/24/09 - 2:04 PM
#2 by Ben Nadel on 9/24/09 - 2:09 PM
validateparams="{ pattern=a{1,5} }"
... throws a syntax.
Honestly, the way they did the validateparams is junky. They should just have used the same method that CFParam does where tehse exist as optional attributes.
#3 by Dan Vega on 9/24/09 - 2:10 PM
#4 by Dan Vega on 9/24/09 - 2:12 PM
pattern: A JavaScript regular expression that the parameter must match; used only for regex or regular_expression validation.
#5 by Micky Dionisio on 9/24/09 - 2:14 PM
This is a fantastic idea. At a glance, the out of the box validation offers quite a lot and coupled with the validationParams keeps it simple and straight forward (goodbye all manual custom if's i have to create in boiler plate validation utility objects). On top of that you've got it working using annotations which makes this entire thing killer.
I see that all validators extend IValidator so its kosher for us to possibly create our own?
Excellent work man - will definitely look out for future releases.
-Micky
#6 by Raymond Camden on 9/24/09 - 2:20 PM
#7 by Mike Chandler on 9/24/09 - 2:21 PM
#8 by Raymond Camden on 9/24/09 - 2:22 PM
#9 by Ben Nadel on 9/24/09 - 2:40 PM
I have tried what I think you are saying and it throws an error that the value must be static.
#10 by Dan Vega on 9/24/09 - 2:41 PM
#11 by Ben Nadel on 9/24/09 - 2:47 PM
#12 by Dan Vega on 9/24/09 - 2:49 PM
#13 by Ben Nadel on 9/24/09 - 2:50 PM
#14 by Brian Carr on 9/24/09 - 2:53 PM
If that's not the case, then please someone speak up and show us the light!
My guess is that the 'implicit struct' is being converted under the covers by CF specific and exclusive only to @validateParams.
#15 by Henry Ho on 9/24/09 - 2:58 PM
#16 by Bob Silverberg on 9/24/09 - 3:01 PM
I designed ValidateThis to allow for different metadata implementations, and I know that this is something that some developers will be keen on (even if I am not myself), so I was planning on adding that feature (validation metadata via property annotations) in a future release. Because of the design it will be a simple matter of adding one new component.
As I believe the goals of these projects are identical, if you see any value in collaborating on this effort, rather than creating an additional project that accomplishes the same thing, I'd be keen to discuss that.
#17 by Dan Vega on 9/24/09 - 10:32 PM
@Bob - I already have the project created and running but I think sharing ideas on the best approach to solving the problem is a great idea. I will pull down your framework again this weekend and take a look at it.
#18 by Bob Silverberg on 9/24/09 - 11:28 PM
#19 by Dan Vega on 9/24/09 - 11:30 PM
#20 by Raymond Camden on 9/25/09 - 8:57 AM
Now pardon me while I move away from that ominous looking storm cloud that just appeared.
#21 by Dan Vega on 9/25/09 - 9:02 AM
#22 by Bob Silverberg on 9/25/09 - 10:21 AM
And while you say that you've "never stolen anything for any of my projects", I would say the same is true of me, but I wouldn't hesitate to say that I've "taken" ideas and in fact code from other OS projects. I think that that is part of the philosophy of OSS. Not just to produce a piece of software that is free and available, but also to put out code that is free and available to be extracted and used in other projects.
So yes, I agree that stealing is wrong, and perhaps should not be a term used in this context, but I think that taking is perfectly fine, and in fact is encouraged.
#23 by Raymond Camden on 9/25/09 - 10:23 AM
#24 by Bob Silverberg on 9/25/09 - 10:30 AM
#25 by Ben Nadel on 9/25/09 - 12:50 PM