Photo from Chile

Customizing Model-Glue by Overriding Framework Components

One of the cool features of Model-Glue version 3 is the ability to replace many of the components that make up the framework with your own version. This allows you to change the default behaviour of the framework (which can be useful) without having to alter any of the framework's internal code (which is a bad idea). Let's look at a situation in which we might want to customize Model-Glue and how we would do it.

Customizing Generated Code

Scaffolding is a feature of the framework that allows Model-Glue to generate working CRUD code for an object when you're using an ORM. Model-Glue 3.1 supports Transfer and Reactor, and Model-Glue 3.2 (coming soon) will also support ColdFusion 9's built-in ORM features. When you ask Model-Glue to do scaffolding for an object it will create event handlers and view templates for the operations that you request, which can include List, View, Edit, Commit and Delete. The code that is generated is based on cfcs that, by default, are found in ModelGlue/gesture/modules/scaffold/beans. The cfcs are called View.cfc, List.cfc, etc.

If we want to change the way the view template is generated for the List action, we can simply edit the file ModelGlue/gesture/modules/scaffold/beans/List.cfc, changing the code to reflect how we want our List view template to be generated.

But wait, didn't we discuss earlier that changing files within the framework itself is a Bad Thing©? No problem. Model-Glue allows you to override its own internal components by pointing to a component that belongs to your own application, which lives outside of Model-Glue's code base.

[More]

Comments
Brian Swartzfager's Gravatar Another thing you can override using this technique is the LogRenderer (the CFC responsible for generating the debugging table at the end of each event if debugging is turned on in the ModelGlue configuration).

It's also worth mentioning that the scaffolding beans (List.cfc, Edit.cfc, etc.) all extend the AbstractScaffold.cfc, so if you want to make a change that affects all of the scaffolding beans, you may want to create your own version of the AbstractScaffold.cfc in your application and have your custom scaffolding beans extend that file instead.

Great post as always, Bob.
# Posted By Brian Swartzfager | 1/11/10 3:40 PM