MG3 Feature Sneak: Event Generation Video

Yesterday on YouTube, I posted a video of a new developer workflow coming in Model-Glue 3 called "Event Generation." When in developer mode, hitting a nonexistent event-handler can be configured to generate a conventions-based Controller, listener function, controller, and view. Basically, typing "index.cfm?event=order.list" gives you the following:
  1. An OrderController will be generated if it doesn't exist
  2. A listener function named "list" will be created in OrderController
  3. A message-listener subscribing OrderController.list() to "order.list" will be generated, along with a controller tag if one does not exist.
  4. A view in /order/list.cfm will be created.
  5. An event-handler tag wiring all of this together is created in the XML file of your choice, defaulting to your main ModelGlue.xml
Here's a video of it in action: One of my favorite features coming in MG3 is purely for developer ease of use: hit an event that doesn't exist while in development mode, and it'll generate intelligently named controllers, listener functions, and views, wiring them all together with convention-based XML. Here's a video of Event Generations (and a bit of SES features) in action:

Model-Glue 3 goes Public @ cf.Objective()

Three years ago, the Model-Glue framework brought easy but powerful MVC development to the ColdFusion community. With the release of Model-Glue 3 (code named "Gesture"), the framework's going back to its roots.

Model-Glue 3 is will make it easier than ever to employ architectural concepts like MVC and Implicit Invocation in your ColdFusion applications.

At cf.Objective() 2008, I'll be showing all of the new features in Model-Glue 3 for the first time as well as some of the revamped framework internals.

Model-Glue 3 "Beans" Injection

One of my favorite features in Model-Glue, suggested and originally implemented by Sean Corfield, is autowiring. With autowiring, if you create a method named setSomeService() on a Controller, the framework will automatically search a ColdSpring bean factory for a bean named "someService" and set it into the controller.

It's super-cool, but it requires some explicit, repetitive code: writing nearly identical setters on your controller for the services it needs.

Model-Glue 3's code name is "Gesture," and it stands for declarative workflows and elimination of boilerplate. Clearly, something had to be done about all these setters that just serve as a marker for autowiring.

In Model-Glue 3, this "something" is a new attribute on the <controller /> tag called "beans":

<controller
    id="contactController"
    type="com.myapp.controller.ContactController"
    beans="contactService,authenticationService"
/>

Inside of each Model-Glue controller is a new scope called "beans" (really, it's just a struct in variables....). When the framework loads, it automagically sets any beans listed in the "beans" attribute of <controller /> into the "beans" scope, keyed by beanId, no setter required.

In other words, as soon as I reload the framework with the above <controller /> tag, I can do this in any listener function:

<cfset var contacts = beans.contactService.list() />

Fun stuff!

Diagram: Relating Model-Glue (ColdFusion) to Cairngorm

I was talking with a ColdFusion developer earlier today who uses Model-Glue extensively and is diving into the Cairngorm framework for Flex and we were discussing the various layers (there are plenty) in a Cairngorm application/

This got me thinking that it might be handle to have a reference that compares the various layers in a typical Model-Glue application to a Cairngorm setup. I've knocked together a diagram doing just that, and it's available as either a PDF or an image (below, save it for full-size).

ColdFusion Disclaimer: It assumes you're using Model-Glue and ColdSpring, but it'd be easier enough to translate it to Mach-ii and other IoC frameworks.

Cairngorm Disclaimer: I glossed over things like responders to show big picture.

Model-Glue group on ColdFusionCommunity.org

ColdFusionCommunity.org, a Facebook-like site for ColdFusion developers, is growing rapidly. Yesterday, Shimju David started up a Model-Glue group. It'd be great if it grew into an "unofficial" place to connect with and get to know other Model-Glue developers.

Model-Glue: New Flex Integration Features

We've discussed this since the dawn of MG (I once had a knock-down argument with Doug Hughes about why this shouldn't be added), but I recently really saw the need for it. It'd be great to be able to add Flex widgets into existing Model-Glue applications without recreating wheels (or refactoring to full service layers), and there are also good cases out there for event-driven Model tiers. Admittedly, ColdBox also lit a fire under me to get this committed into SVN.

I've been working for the past few months, on and off, to add not just Flex integration but smooth Flex integration into Model-Glue. It's now committed to SVN, and you're welcome to use it. There's a new CFC in the application template (RemotingService). To make it part of your application, make a copy of it wherever you'd like and change the four variables it defines. Its base class does the rest.

A picture may say a thousand words on how to use this. I'll shoot for ten thousand: here's 13-minute a video.

If you'd like to skip the video, here's the highlights:

RemotingService.cfc acts as a Flash Remoting or SOAP endpoint for your application. If you didn't want any niceties on the Flex side, you could simply do this:

<mx:RemoteObject
    id="mgProxy"
    source="myapp.RemotingService"
    destination="ColdFusion"
/>


<mx:Script><![CDATA

// invoke a model-glue event
mgProxy.remoteEvent("widget.list", data);
]]>
</mx:Script>

...adding result and fault handlers as necessary. That's not too clean though: since there's only a single method to call, you'd have to have your result figure out which event was called, delegate to a per-event handler, etc.

To make things nicer, I've wrapped deailing with Model-Glue's RemotingService into a .SWC that I'd recommend anyone doing this take advantage of. It's what I've put a fair amount of time into in order to make using Model-Glue from Flex "just work." It's in ModelGlue/unity/flex/bin/ModelGlueRemoting.swc, and contains three classes:

  1. com.modelglue.ModelGlueDelegate - Wraps a RemoteObject instance and provides an "invokeEvent" method allowing passing of an event name, parameters, and callback functions.
  2. com.modelglue.ProxyRequest
  3. - The result of calling invokeEvent on a RemotingService, containing event data, the trace log, etc. Maps to the ModelGlue.unity.proxy.ProxyRequest CFC.
  4. com.modelglue.TraceGrid - DataGrid to show a Model-Glue event log.

To add it, just drop a copy of the .swc into your Flex Builder 3 project's "libs" directory, or use properties -> Flex Build Path -> Library Path to add a reference to the .swc to your project.

Once it's added, you no longer use the RemoteObject tag. Instead, you use the Model-Glue delegate:

<modelglue:ModelGlueDelegate
    id="mgDelegate"
    source="myapp.RemoteService"
    destination="ColdFusion"
/>

Invoking an event now takes one required argument (the event name) and three optional arguments (an Object of event data, the result function for the call, and the fault function for the call). Here's how we'd get Widget with Id of 2:

mgDelegate.invokeEvent("widget.get", {widgetId:2}, widgetGetResult, widgetGetFault)

private function widgetGetResult(e:ResultEvent) {
    // do stuff

}

private function widgetGetFault(e:FaultEvent) {
    // do stuff

}

Easy, eh?

There's more. The "result" member of the ResultEvent is an AS3 class called com.modelglue.ProxyRequest. Its "data" member contains all the values from your event, so they're immediately available to you in Flex. Its "log" member contains the full Model-Glue trace, and there's even a custom DataGrid to help you show it!

Let's pretend we wanted to read widget with WidgetId 2 and see the trace. We can add the trace grid:

<modelglue:TraceGrid id="traceList" width="100%" height="100%" />

Now, we update our result to get the widget into a variable (AS3 <-> CFC conversions work!) and trace the event log:

private function widgetDeleteResult(e:ResultEvent) {
    request:ProxyRequest = e.result as ProxyRequest;
    
    // a "widget" variable was created by the MG event

    someWidgetForm.widget = request.data.widget;

    // show our trace log

    traceList.dataProvider = request.log;
}

If Model-Glue encounters an exception, that'll be noted as well. Your ProxyRequest's "exception" property will be true, and the data.exception and data.stackTrace will be populated. "Exception" is basically the cfcatch structure, and the stackTrace is the full ColdFusion stack trace to the exception.

All of this is committed into SVN, and should make it into an official dot release after feedback is collected and revisions made.

Use of Model-Glue.com content (Logos, etc.)

Talk about a post I didn't think I'd wind up writing when I started Model-Glue! With the advent of commercial endeavors using Model-Glue as part of their advertising, this became necessary. Please be aware that the terms listed below only apply to using the Model-Glue.com logo and content, not the framework itself! The framework is and will be under the Apache Software License 2.0.

Summary

You're free to use any of the Model-Glue site content or graphics in noncommercial, educational, open-source, or personal contexts. If you're using it for commercial purposes (basically, if having the Model-Glue.com logo or other content as part of something that's making you or your company making money), you'll need to attribute its copyright as described below.

Use of the Model-Glue Logo and Web Assets

The content of Model-Glue.com is not licensed under the Apache Software License 2.0. It and the Model-Glue web site are two separate works. The Model-Glue web site, its content (except blog entries contributed by other authors), and all of its assets ("Model-Glue.com content") are the intellectual property of Joe Rinehart of Firemoss, LLC. Reproduction or derivative use of the Model-Glue web site, its content, or its assets are subject to the following terms.

Noncommercial, Open-Source, and Personal Use

Use of Model-Glue.com content in non-commercial works (including but not limited to educational, open-source, and personal projects) is free and unlimited. An attribution (e.g., "Model-Glue is Copyright [year], Joe Rinehart, Firemoss, LLC") linking back to http://www.firemoss.com and http://www.model-glue.com is appreciated, but not required.

Commercial Use

Use of Model-Glue.com content in commercial works (including but not limited to software products, web sites, documents, and promotional materials) must conform to the following terms:

Logo Modification in Commerical Works

You may not modify the Model-Glue.com logo except to alter its size. The logo, in its original size, is shown below on a black background:

Use in Linkable Works

In any format that allows hypertext (Web) links ("Linkable Works"), the source of Model-Glue.com content must be attributed, with links, as follows:

<a href="http://www.model-glue.com">Model-Glue</a> is Copyright [year], <a href="http://www.firemoss.com">Joe Rinehart, Firemoss, LLC</a>.

For example:

Model-Glue is Copyright 2007, Joe Rinehart, Firemoss, LLC.

This attribution must appear on each Web page (or other linkable document) using Model-Glue.com content, and must be presented in a legible manner.

When graphical Model-Glue.com content is used, the images themselves should link to http://www.model-glue.com.

Use in Offline Work

Model-Glue.com content may be used in commercial documents.

Attribution of source must be given, but does not need to be given on each page of the document.

Bibliographic attribution in a standard format (e.g., MLA) is acceptable.

The same format as used in Web context is also acceptable. This allows works such as common word processing documents and rich e-mails, which are commonly a Linkable Work, to be printed (becoming an Offline Work) with attribution remaining intact.

Terms Subject to Change

Joe Rinehart reserves the right to change these terms at his sole discretion without any obligation to notify users of Model-Glue.com content.

Model-Glue SVN and Trac moving - short outage 8/20/07!

Simeon Bateman, who's kind enough to host the Model-Glue SVN and Trac sites (as well as sites for Reactor and Fusebox!) informed me that he's going to be upgrading the server later today.

This'll mean a DNS change, so we'll likely see a brief outage while everything gets sync'd up.

Dynamically adding <views/> to a Model-Glue Event

Mark Drew hit me up with an interesting question this morning: can you dynamically add views to a Model-Glue event, determining which views to include at runtime, what to name them, and what template they should use? Yes, you can, and you can do it without mixing configuration information into the controller tier.

[More]

Model-Glue: Simpsons!

The Simpsons Movie web site has a great flash app where you can represent yourself as a Simpsons character.

What better use for it than to put together the first "team portrait" of those involved in Model-Glue?


(Click to Enlarge)

More Entries

© 2018 Joe Rinehart
BlogCFC was created by Raymond Camden. This blog is running version 5.9.3.006.