Unfortunately, cf.Objective 2010 was not in the cards for me this year, and I apparently missed out on many marvelous sessions. I would have been particularly interested to attend Dan Wilson’s “Speedy Gonzales Guide to Model-Glue” session, as Model-Glue 3.2 promises to be a great release. Model-Glue 3.2 Alpha is currently available for download, and the Model-Glue gang are now welcoming those who wish to help test the framework in its current phase. Details for how to become involved can be found at the official Model-Glue website.
Some would argue that one of Model-Glue’s best features is the ability to create scaffolds. “Scaffolds are a tool by which you can very rapidly create basic user interfaces for editing the contents of a database table.” As you might imagine, this ability saves a lot of time and effort that can be put toward more innovative endeavors. When I last looked at scaffolding, about a year ago, I certainly saw the value. At the time, though, it lacked a few things I needed. Having seen what it can do as of Model-Glue 3.2, you can bet I will be implementing this capability in the very near future. Let’s have a quick look.
For my first dive in, I used a sneak-peek walk through kindly provided to me by Dan Wilson, of DataCurl, and written by Alagad’s own Ezra Parker. It incorporates the work of many other fine members of the Model-Glue team. My goal for the moment will be to pique your interest. If you hop over to the Model-Glue Google Group and offer your assistance, you might just get an inside looksee for yourself!
Reactor was the ORM chosen for this tutorial. However, scaffolding also works with Transfer and CF9ORM. Upon install, the sample application was configured for basic scaffolding. Of course, the features were not apparent. I still had some work to do. (I use the term “work” loosely!)
My first task was to add scaffold tags to the ModelGlue.xml file as such:
(Apologies for the screenshot shortcuts to showing you some code. I gotta hit the road to NCDevCon, and I’m apparently incapable of working with the blog engine today.)
At this point, the tutorial tells me, “basic scaffolding functionality is in place, and clicking on any of the generated navigation items will take you to the list view for the table/object in question.”
Wow, that was easy. Voila. As promised, a navigation menu appears up top.
Here’s what the form for adding a new post looks like:
There she is… impressive functionality for minimal work on my part. Yet, it was still somewhat aesthetically blah and in need of a makeover. This will take some doing, though, won’t it? Last time I tried this, I eventually grew frustrated to the point where re-inventing the wheel seemed easier. Not so, this time! My next task was to pop open the ColdSpring.xml config file and replace this line:
C’mon… really? All I have to do is instruct this thing to get “fancy”, and it will? YES! Ok, so I also had to uncomment the CFUniFormConfigBean bean and various custom scaffold beans. Then, I went into the application controller to add a bean attribute to the cfcomponent tag and a cfset to the onRequestStart() function.
Yummy. Bean injecty goodness. At this point, I’m told that reloading the application will reveal a “dramatic” difference in appearance. It sure did. For starters, I saw this comparatively pretty form… complete with a jQuery date picker!
Who among us doesn’t love some jQuery strewn about our forms? That’s not all we’ll see of it, either. The various other forms and list views were nicely decorated, as well. Uber awesome, to be certain.
From here, the tutorial moved into object/table relationships. In this case, I added various object tags to the Reactor.xml configuration file. This bit might look familiar to you. The concept isn’t new. The outcome, however, is somewhat different.
With that, and a few more blocks of code similar thereto, we have a many-to-many relationship in place, as well as a one-to-many and a many-to-one. What’s impressive this time around, though, are the controls that were added to represent these relationships. More jQuery joy in the form of a multiSelect widget and a dataTables widget.
You can’t tell me you’re not impressed at this point. This is good stuff, especially since at this point I’ve put about 10 minutes worth of effort toward scaffold configuration.
And finally, we’re down to customizing the scaffolds. According to the tutorial, “there are a number of different ways to customize the results of the files generated by scaffolding.” It goes on to describe the comprehensive approach of overriding the scaffold beans and custom tags in Model-Glue’s core with your own stuff. For the duration of this demo, though, we just picked over a few things after the views had already been generated. Behold the granular control you now have over your scaffolding. Top notch stuff, so says I.
Basically, I just copied the Form.Post.cfm file from /BlogOMatic/views/generated/ up to the /BlogOMatic/views directory. That shouldn’t be unfamiliar territory, as it’s a common way of overriding an autogenerated file with your own custom file. Move it out into the appropriate root from the subdirectory where generated files are stored for that layer and make your changes there.
The tutorial had me re-order some of the scaffold tags and rename label attributes. I had a bit of my own fun and added some avatars to the user display.
You’ve only seen a smidgen here of what I witnessed. The non-Model-Glue-aware coder would look at the demo application and assume someone spent a substantial amount of time getting it to the point where this tutorial left it.
So now that I have you enthralled with the topic of Model-Glue 3.2 and scaffolding, why not take a moment to visit the official Model-Glue blog to find out how you can help! By becoming a Model-Glue 3.2 Alpha Tester, you can take pride in knowing that you helped make the best ColdFusion framework even better. “You’ll also get more personal time and instruction with the Model-Glue team in how to use these features.” They’re not kidding, either. I once had the pleasure of a one on one with Managing Director, The Great Dan Wilson Himself. It was powerful… it was magical… I gave it a 10!
By the way, If you missed Dan at cf.Objective, it looks like you have several opportunities to catch him at CFUnited 2010, and I’m sure he would also like for me to remind you that there may still be time to register for NCDevCon which takes place THIS Saturday and Sunday. We gotta show these Scotch on the Rocks folks that East Coasters know how to party. Will YOU be there? I will. If you see me, say hello. I don’t bite very hard.