An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

Fusebox 5 in a Model-Glue style

June 17, 2006 · 3 Comments

I blogged about this a while back as an example of the power of custom lexicons. Over the last 24 hours, I completed enough of the Model-Glue custom lexicon to allow my original Model-Glue sample application to run as a Fusebox 5 application. You can download ggcc7fb5.zip and have a look - and if you have Fusebox 5 Beta 2, you'll be able to run it.The example includes the Model-Glue lexicon: which provides a Model-Glue style syntax but running entirely natively in Fusebox 5. You could have a circuit in this Model-Glue style (perhaps a Model-Glue 1.x application converted to a Fusebox 5 circuit, as in this example) alongside regular Fusebox circuits. What changes did I have to make to the Model-Glue example to get it to run? I stripped the extends=, returntype= and type= attributes out of the controllers and replaced the (few) init() methods with simple pseudo-constructors, initializing variables directly from application.fusebox parameters (OK, that's a bit of a hack). Then I copied all of the controller declarations out of the ModelGlue.xml file into fusebox.xml.cfm and made them class declarations with custom attributes to specify the listeners. Finally I did a few find'n'replace operations on the event-handlers to turn them into fuseactions that used the mg: custom lexicon for the verbs. Here's an example fuseaction:
<fuseaction name="showmanager">
         <mg:broadcasts>
            <mg:message name="checkIdentity"/>
            <mg:message name="needMembers"/>
            <mg:message name="needMembersByID"/>
            <mg:message name="needTasks"/>
            <mg:message name="needStatii"/>
            <mg:message name="needStatiiByID"/>
         </mg:broadcasts>
         <mg:views>
            <mg:include template="dspShowTaskList.cfm" name="content">
               <mg:value name="XFA.AddTask" value="ggcc.newtask"/>
               <mg:value name="XFA.ChangeIdentity" value="ggcc.identify"/>
               <mg:value name="XFA.TaskDetail" value="ggcc.showtask"/>
            </mg:include>
            <mg:include template="layGGCC.cfm"/>
         </mg:views>
      </fuseaction>
Here's the original Model-Glue event-handler:
<event-handler name="ggcc.showmanager">
         <broadcasts>
            <message name="checkIdentity"/>
            <message name="needMembers"/>
            <message name="needMembersByID"/>
            <message name="needTasks"/>
            <message name="needStatii"/>
            <message name="needStatiiByID"/>
         </broadcasts>
         <views>
            <include template="dspShowTaskList.cfm" name="content">
               <value name="XFA.AddTask" value="ggcc.newtask"/>
               <value name="XFA.ChangeIdentity" value="ggcc.identify"/>
               <value name="XFA.TaskDetail" value="ggcc.showtask"/>
            </include>
            <include template="layGGCC.cfm" name="final"/>
         </views>
      </event-handler>
Bear in mind, this is mimicking Model-Glue 1.x - I don't plan to attempt to mimic Model-Glue 2.0! It also only mimics enough of the syntax to make the example work. It's just an illustration of what Fusebox 5 custom lexicons let you do.

Tags: coldfusion · fusebox · modelglue

3 responses so far ↓

  • 1 Mike Brunt // Sep 26, 2006 at 4:18 PM

    Thanks Sean this will be really useful for us. We have to completely redesign and legacy CF App and had been looking hard at MG. I just feel that FB5 might be a better transiotion for the developers here.
  • 2 Nathan Stanford // Oct 19, 2006 at 6:31 PM

    Where can we find a sample FB5 app that shows not putting all of the view files in one dir? Like of you have a huge application you don't want to put all the view or model files in one folder... that would be crazy.

    Thanks,
    Nathan
  • 3 Sean Corfield // Oct 19, 2006 at 9:11 PM

    @Nathan, the sample apps are usually too small to warrant having multiple view circuits. You can have as many model and/or view circuits as you want. I suggest you join the Fusebox 5 mailing list and search the archives as this question has been asked (and answered) more than once.

Leave a Comment

Leave this field empty: