Introducing validORM: A Development Tool for Creating ORM CFC And ValidateThis Files

AngularJS , CFML , ColdFusion Add comments

In my previous post about relating different data constructs in AngularJS to each other via property names, I mentioned that I figured out that technique while working on an internal development tool.  This blog post is about that tool.

The AngularJS-powered validORM tool lets you design the ID and column properties of your ColdFusion/CFML ORM CFCs while at the same time creating a matching set of validation rules using the ValidateThis (VT) library (a great library for handling both client and server-side validation).

The first view of the tool is a menu view.  You can choose to generate an updated version of your CFC and VT rules file based on a previous session or create a new set of files from scratch.  Either choice takes you to the generator view.

The first two sections of the in the generator view are pretty obvious:  that's where you choose the name and database table for your ORM object and configue the ID property.

The third section, where you define your column properties and create your validation rules, is where AngularJS really comes into play.  The property drop-down selection, the form controls and the hover hints for each property attribute you add, and the validation rule options and parameters:  those are all AngularJS manifestations of JavaScript data constructs.  Using the "Add Attribute" button to add a property attibute simply adds a JavaScript object of that name to the dataset; the creation of the form elements on the page for that attribute is handled automatically by AngularJS based on the Angular directives in the HTML.  That's Angular's strength: driving page behavior purely through data manipulation. 

The data constructs created by your choice of property attributes and validation rules are separate from the JavaScript objects and arrays of objects that represent all of the attribute and rule options, but they reference each other via the attribute and rule key names.

The last two sections allow you to further define any ValidateThis conditions and contexts referenced in your column property rules.  When you're done, clicking the submission button will trigger the file generation process.  Your ORM and VT configuration data will be parsed by a CFC which will then generate three files in the output folder of the tool:

  • An ORM CFC written in script format.
  • A ValidateThis rules definition file matching that CFC written in JSON format.
  • A JSON-formatted snapshot of the configuration data, with a filename reflecting the name of the object and the timestamp when the file was generated.  Said file will then appear in the menu view of the tool.

Some caveats:  the tool only allows for one ID property, doesn't include absolutely every type of property attribute (just the majority of them), and it doesn't let you define ORM relationship properties.  And as my first foray with using AngularJS, I'm sure it violates one or two Angular best practices (if you're an Angular guru, feel free to chime in with any suggestions for improvement).

But it works and can provide a kickstart to creating any ORM files and ValidateThis rules for your projects.  It comes with an example "Employee" configuration set that you can play with and then delete once you start using the tool.

The tool is available for download (and modification) via GitHub:  https://github.com/bcswartz/validORM. I also created a short video of the tool in action and posted it on YouTube at: http://www.youtube.com/watch?v=-fnt_n65NWg

5 responses to “Introducing validORM: A Development Tool for Creating ORM CFC And ValidateThis Files”

  1. Chuck Duppong Says:
    Brian,

    I'm trying out validORM; perhaps I've missed something- when I click on the example Employee link nothing loads. The dropboxes are always empty (in FF and Chrome).

    Thanks
  2. Brian Swartzfager Says:
    @Chuck: Hmm. The drop-downs on the generator page are populated based on the .json files in the /data directory of the tool. So that implies that Angular failed to load them, and if that's so, then Firebug or the Chrome console ought to denote those failures.

    What's your environment (OS, webserver, CFML server)? I doubt it's a CFML server issue: if it were, you wouldn't have gotten the Employee link to begin with.
  3. Chuck Duppong Says:
    I'm running Windows 7 Enterprise (32bit) and Cf 9.0.1.

    In the Chrome console, I do see it fail to load these 4 files with a "404 (Not Found)" (angular.min.js line 99)

    ormtypes.json
    generatorOptions.json
    columnPropertyAttributes.json
    ValidateThisRules.json

    The files are present and have data in them.
  4. Brian Swartzfager Says:
    @Chuck: I don't have Win 7 Enterprise, but I've tried validORM on my Windows 7 machine with Apache as the web server and it works fine.

    Are you running Apache or IIS? I'll admit that I didn't test it with IIS, and a Google search on "IIS and JSON files" pulled up a few results indicating that some versions of IIS need to be configured to read .json files.

    Let's try this: I'll email you a new version of validORM I just made that uses the .txt extension for all the files (except the VT rules files that get created), and we'll see if it works for you when configured that way.
  5. Chuck Duppong Says:
    Brian,

    The version with .txt extensions worked like it should.

    I'm running IIS. I went into the IIS Manager and added a json Mime type.

    That was what it needed, and the original version works now.

    Thanks!

Leave a Reply