Orange is my favorite color

Following up on my post from yesterday, here are a few things I’ve learned in the last 24 hours:

Findings Today

  1. eXit Events – I’d been toying with these but I am going to commit to using them exclusively with viewState.getValue(‘myself’) in order to fully control the application flow from model-glue.xml. This goes even for “static” links:
    model-glue.xml:
    <event-handler name="public.terms">
    	<views>
    		<include name="main" template="public/terms.cfm">
    			<value name="xe.privacy" value="public.privacy" />
    			<value name="xe.contact" value="public.contact" />
    		</include>
    	</views>
    	<results>
    		<result do="view.pap" />
    	</results>
    </event-handler>
    
    terms.cfm:
    <h4>Privacy Policy</h4>
    <p>
    	View our < a href="#myself##xe.privacy#">complete privacy policy< /a>.
    </p>

    The advantage is, besides Mark Drew’s points on changing the MG key, that I can completely change the flow of the application by only modifying a single file: model-glue.xml. I think that will be nice. Although it does make that file bigger with all of those XEs in there.

  2. View Stacking – I’ve been using a series of custom tags imported as taglibs for years to handle UI wrappers in my sites. Effectively I import a directory full of small files that use the thisTag and attributes scopes and then use them to layout the pages I’m working in like:
    <ui:page name="Name of Page" layoutClass="widescreen">...</ui:page>

    I was having a hard time figuring out how to replace these tags with views in MG. Thanks to Dan Wilson, the answer was all too simple: use an intermediate view step to set these dynamic properties. Now I’m doing this:

    model-glue.xml:
    <event-handler name="public.terms">
    	<views>
    		<include name="main" template="public/terms.cfm">
    			<value name="xe.privacy" value="public.privacy" />
    			<value name="xe.contact" value="public.contact" />
    		</include>
    	</views>
    	<results>
    		<result do="view.content-ma" />
    	</results>
    </event-handler>
    <event-handler name="view.content-ma">
    	<broadcasts />
    	<views>
    		<include name="layout" template="layout/pap/content-ma.cfm" />
    	</views>
    	<results>
    		<result do="view.pap" />
    	</results>
    </event-handler>
    <event-handler name="view.pap">
    	<broadcasts>
    		<message name="needThemeConfig" />
    	</broadcasts>
    	<views>
    		<include name="header" template="layout/pap/header.cfm" />
    		<include name="footer" template="layout/pap/footer.cfm" />
    		
    		<include name="template" template="layout/pap/template.cfm" />
    	</views>
    	<results />
    </event-handler>
    
    content-ma.cfm:
    <div id="content-ma">
    
    I also have content-m.cfm:
    <div id="content-m">
    
    and content-am.cfm:
    <div id="content-am">

    Based on the class of this div, the CSS controls the layout (single wide column, skinny left and wide right or wide left and skinny right). So these three little files with their one line each are then brought into the template.cfm like:
    <cfoutput>#viewCollection.getView("layout")#</cfoutput>
    Now in my model-glue.xml, I can just swap from pap.content-ma to pap.content-am and the columns reverse – exactly the same control as I had before with my layoutClass parameter to ui:page. Thanks Dan!

  3. Directly accessing arrays returned from methods – If you have a method that returns an array and try to access it you will get an error. Say you had an array of structs and you wanted a value:
    foo = someObj.someMethod()[1].value;
    No dice. To workaround, you would need an intermediate variable which sucks. Extra coding for no extra value. “Zeros” from IRC gave me an alternative java syntax that works:
    foo = someObj.someMethod().get(0).value;
    It uses a zero-based index and turns 3 lines of code into one in most cases for what I’m doing.

Questions Today

  1. EventPalooza – It seems like you have at minimum two events for editing data – the form and the process events. If you can list it, that’s 3. Add a delete step and you’ve got 4. Now if you’ve got any kind of event stacking it might be some multiples of that. Whew… the model-glue.xml is getting big in a hurry.

Resources Today

  • Mark Drew’s Model Glue tips category
  • IRC on irc.dal.net in #modelglue and #coldfusion

2 Comments

  1. Dan Wilson said:

    on January 5, 2008 at 7:36 am

    Brian,

    Keep in mind, ModelGlue has a scaffolding feature which will help you create admin screens.

    Secondarily, you can look at the Generic Database Messages if you have your ORM plugged in.

    From the documentation at docs.model-glue.com

    The four GDMs that the DataController is configured to listen for are as follows:

    1.

    modelglue.GenericList

    When this message is broadcast, the DataController will attempt to list records from a given table.

    2.

    modelglue.GenericRead

    When this message is broadcast, the DataController will attempt to read a specific record from a given table.

    3.

    modelglue.GenericCommit

    When this message is broadcast, the DataController will attempt to save a record to a given table.

    4.

    modelglue.GenericDelete

    When this message is broadcast, the DataController will attempt to delete a record from a given table.

    Don’t work any harder than you have to.

    DW

  2. brian said:

    on January 5, 2008 at 3:49 pm

    Dan – thanks for the tip. I’ve already got a complete API for this from my existing application that I refactored earlier. There is only a very small portion that doesn’t require “nice” admin screens with workflow and I have a lot of foreign key/composite keys that Transfer doesn’t handle yet.

{ RSS feed for comments on this post}