Mark Drew (Redux)- cf_etc...

a compendium of railo, cfml, cfeclipse and technology topics

Mark Drew (Redux)- cf_etc...

Adding event variables to ModelGlue.xml

January 8, 2007 ·

When using Joe Rinehart's Model-Glue framework, I noticed a few people that come from using fusebox based apps were a bit confused at how you would set either application wide variables, or fuse-action (i.e. event) specific variables (such as xfa's). In the definition of MG itself there isn't something blatantly obvious, so how would you set, for example, the section variable that each of the event-handlers belongs to (for the title for example)? In the controller, I created a function called setValue, this function loops through any arguments you pass to them creating event values for them: <cffunction name="setValue" access="public" returnType="void" output="false">
       <cfargument name="event" type="any">

       <cfset stArguments = arguments.event.getAllArguments()>
       <cfloop collection="#stArguments#" item="arg">
       <cfset arguments.event.setValue(arg, stArguments[arg])>
       </cfloop>

    </cffunction>
I can then set an event constant in the event-handler, by broadcasting the following message: <broadcasts>
      <message name="setValue">
         <argument name="xfa.section" value="testimonials" />
      </message>
   </broadcasts>
This means that in my view code I can get the section variable as follows: <h1>#ViewState.getValue("xfa.section")#</h1> In my next post, I shall set some application wide variables, and show you how to access them in a similar manner. EDIT: Andy Jarett has just pointed out something (which should have been as plain as the nose in my face) that instead of having to do the above, you can simply do the following for each include: <views>
      &amp;lt;include name="body" template="dsp_body.cfm"&amp;gt;
         <value name="xfa.section" value="testimonials" />
      </include>
   </views>
Which is obviously the easier way of doing it (if you bother to read the documentation, which I didn't).

Tags: coldfusion · model-glue

3 responses

  • 1 Sal // Sep 22, 2008 at 4:10 PM

    Right as reading the post I was just gonna comment on Andy's correction...

    cheers.

    Sal
  • 2 Mark Drew // Sep 22, 2008 at 4:10 PM

    I realised (after talking to Joe) that they added this a while ago, I remember reading some of the discussion and thought Joe wasnt going to add it, this was a LONG while back, so probably I had it stuck in my head that there wasnt going to be this feature. Hence the solution above.

    I know that it sets it for all the event thereafterm, but I prefer to have it in the broadcast, rather than in one include (I might have a number of includes) but I conceede defeat... but then again, it just shows that MG rocks sometimes :D
  • 3 Sam Clement // Sep 22, 2008 at 4:10 PM

    Thanks for the post, Mark. It reminded me that I needed to re-look into XEs AND re-read the docs! Love MG.