![]() |
|
|
Hyrule
Project Home • Wiki • Known Issues • Contact Project
Author: Dan Vega (All RIAForge projects by this author) Description:
Validation has always been a tedious process that I wanted to rid my self of. I have used various frameworks that are out and many iterations of my own. I don't think you can really use other frameworks until you understand the problem and how the problem is solved. With that In mind I wanted to tackle my own validation framework. The idea for this framework really came from 2 sources. I really enjoyed the way the QuickSilver framework was using annotations in there framework so I thought I would do the same. The other source of inspiration was the hibernate validation frameowrk. That framework does the same thing for validation and many of my constraints, example and documentation text come from that framework.
Annotations are a very convenient and elegant way to specify invariant constraints for a domain model. You can, for example, express that a property should never be null, that the account balance should be strictly positive, etc. These domain model constraints are declared in the bean itself by annotating its properties. A validator can then read them and check for constraint violations. This is an example of a user component with some annotations sprinkled in. /** * @output false */ component { property numeric userId; /** * @display First Name * @NotNull */ property string firstname; /** * @display Last Name * @min 3 */ property string lastname; /** * @display Username * @max 1 */ property string username; /** * @display Password * @Range 6,10 */ property string password; /** * @display Email Address */ property string email; public User function init(){ return this; } } Creating an instance of our domain object and passing it to our validation framework. user = new User(); user.setFirstName(""); user.setLastName("a"); user.setUsername("myusername"); user.setPassword("myreallylongpassword"); user.setEmail("thisIsNotAValidEmailAddress"); hyrule = new hyrule.Validator(); hyrule.validate(user); writeDump(user); writeDump(hyrule.hasErrors()); writeDump(hyrule.getErrors());
Requirements:
ColdFusion 9
Issue Tracker:
To enter issues for this (or any other) project, you must be logged in. |
||||||||||||||||||||||||||||||||||||||||||||||||
Adobe and the Adobe product names are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries.