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: 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.

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 2.0 (Unity): Release at CFUnited!

Well, I guess this sort of binds me to finishing it. As part of his new role as Community Manager for Model-Glue, Ray's asked me to commit to a release date for Model-Glue 2.0, a.k.a., "Unity". So, here goes: the .zip of Model-Glue 2.0 will be available when CFUnited starts. I can't guarantee all the open tickets will be closed, or that the documentation will be 100%, but I've set aside a ...

[Read more on Joe Rinehart's blog]

Model-Glue List: No more Topica!

The Model-Glue e-mail list is finally off of the dreaded Topica engine. Thanks to Ray, it's been moved over to Google Groups a http://groups.google.com/group/model-glue, and the Model-Glue homepage now links to it. I guess our next task is a real Model-Glue.com!

[Read more on Joe Rinehart's blog]

Model-Glue.com Outage

Not that it's a giant loss, but Model-Glue.com/net/org will be on and off today as DNS changes take place. Sorry for any inconvenience. This will not effect the Trac or Subversion sites.

[Read more on Joe Rinehart's blog]

Frameworks Explorer Eclipse Plug-In

Mark Drew has released an absolutely fantastic visual "explorer" of your framework XML files, available over at his web site. With it, you can drill through ColdSpring, Model-Glue, Mach-II, Fusebox, Reactor, and (I think?) Transfer XML configs, letting snippets-based assistants aid in manag...

[Read more on Joe Rinehart's blog]

Raymond Camden joins Model-Glue

I'm proud of the Model-Glue project and its code. Its community support, however, is somewhat of a sore spot with me. It's hard to know what you're good at until you try something. I've tried being a community leader for an OSS project, and I've found out I'm not very good. Without any more fluffiness: today at cf.objective, Raymond Camden agreed...

[Read more on Joe Rinehart's blog]

Model-Glue:Flex?

I figured I'd better blog this while I had some downtime at the cf.objective conference. In my Model-Glue session today, I previewed an experimental AS3 Model-Glue implementation of Model-Glue, providing a lighter weight / looser / more implicit architectural framework in comparison to something like Cairngorm. There's no docs, I've written one sample app, and I'm not sure this'll ever be an '...

[Read more on Joe Rinehart's blog]

Model-Glue: Rendering Excel, E-mail, and alternate formats

Ray Camden posted a question to the Model-Glue list earlier today that was related to how he could use Model-Glue to render an Excel spreadsheet (via the HTML table -> <cfcontent> method) and access the rendered HTML from within a controller. It's pretty straightforward to do the rendering with a simple view that contains a <cfconte...

[Read more on Joe Rinehart's blog]

More Entries

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