News, views, tips and tricks on Oracle and other fun stuff

Model-Glue FAQ

The following are some Model-Glue notes (in the form of an FAQ) I wrote for my own reference. Please feel free to add or correct anything by commenting below.


Which view in the view stack is displayed to the user?
Only the last view rendered is the one that is shown to the user.

Where are the HTML form and URL variables stored?
All HTML form and URL variables are stored in the ModelGlue.Core.Event object.

What is the order of firing events?
explicit results (those with a name attribute) will fire before implicit results (those without a name attribute).


How to send data to a view?
To send data (including complex data types) to a view, use arguments.event.setValue("name", value)

How to access configuration settings in ModelGlue.xml?
To access the configuration settings in ModelGlue.xml (what’s between <config> and </config>), use GetModelGlue().getConfigSetting("settingName")

How to invoke a mapped event?
To map a result to an event and invoke the event use arguments.event.addResult("eventName")

How to get a reference to a config bean?

<cfset appConfig = GetModelGlue().GetConfigBean("yourBeanFile.xml")>

then use appConfig.getSettingName() to fetch the setting value.

How to access message arguments?
Use arguments.event.getArgument("name")


How to send data to a view?
To send data to a view use the <value> tag inside the <include> tag like this:

<event-handler name="dosomething"> <views> <include template="view.cfm" name="body"> <value name="name" value="value" /> </include> </views> </event-handler>

You can specify whether or not to overwrite the value if it exists by adding the attribute overwrite=”true” or overwrite=”false” to the <value> tag.

How to append to an existing view?
If we give an include tag a non-unique name, but add ‘append=”true”‘ to its attributes, it’ll add to the existing view’s content.

<event-handler name="dosomething"> <views> <include template="view1.cfm" name="body" /> <include template="view2.cfm" name="body" append="true" /> </views> </event-handler>

If ‘append=”true”‘ is not present, it’ll overwrite the existing view.

Can I have more than one controller declaration in ModelGlue.xml?
Yes, you can have multiple controller declarations, but each has to have a unique controller name.

Can multiple controllers listen to the same message?
Yes, multiple controllers can listen to the same message; In fact, they can listen more than once if they like. This is valid:

<controller name = "Controller1" type = "Controller1"> <message-listener message = "Message" function = "DoFoo"> <message-listener message = "Message" function = "DoBar"> </controller> <controller name = "Controller2" type = "Controller2"> <message-listener message = "Message" function = "DoTarfu"> </controller>

Should I declare a message-listener for every function in my controller?
No. Declare message listeners only for those functions that need to respond to messages.

Should the name of a message be the same as the name of the corresponding function in the controller?
No, they can be different. Both of the following are legitimate:

<message-listener message="OnRequestStart" function="OnRequestStart" /> <message-listener message="needLoginStatus" function="getLoginStatus" />

Are there any special messages built in into the framework?
In ModelGlue.xml, you can map the following special messages to functions in your controller:

onRequestStart: Put here any code that you need to execute at the start of each request.
onRequestEnd: Put here any code that you need to execute at the end of each request.
onQueueComplete: Put here any code that you need to execute after all views have been added to the queue and before they are rendered.

In case of multiple controller declarations, is the execution order of the OnRequestStart message listeners guaranteed ?
No, there is no guarantee of execution order.

Can I add arguments to my messages?
Yes, you can add an argument to a message like this:
<message name="dosomething"> <argument name="name" value="value" /> </message>
You can then read the argument in the corresponding function in your controller like this: arguments.event.getArgument("name")


How to send data to the view or views that are rendered after the current one in the stack?

How to read data sent from a controller, ModelGlue.xml or a previous view in the stack?
Use viewState.getValue("name", "default value")

How to check the existence of a view in the view stack?
Use viewCollection.Exists("viewName")

How to display the content of a previously defined view?
Use viewCollection.getView("viewName")


Filed in ColdFusion on 24 Jun 05 | Tags: ,

Reader's Comments

  1. |

    Hello, Thanks for showing the FAQ’s here, it helps! Do you have any example DB driven apps that can be downloaded to show how it would look from start to finish? MG has the Contact Manager example but it has no DB references in it. Thanks in advance, Tim

  2. |

    Tim, take a look at Sean Corfield’s sample applications.

  3. |

    Eddie, thanks for leading the blind (and a huge thanks to Sean for making it available before the conference). Cheers

  4. |

    Eddie, nice post! Sorry I didn’t comment sooner.

    For “Can I have more than one controller declaration in ModelGlue.xml?,” I’m not sure if the answer is clear.


    “Yes, you can have multiple controllers but unique message names across controllers.”

    Was “message names” supposed to be “controller names”? Each controller does need a unique NAME attribute.

    If it is in reference to messages, multiple controllers can listen to the same message – in fact, they can listen more than once if they like. This is valid:

  5. |

    D’oh, my text was escpaped. w/o symbols:

    controller name=”Controller1″ type=”Controller1″ message-listener message=”Message” function=”DoFoo” message-listener message=”Message” function=”DoBar” /controller

    controller name=”Controller2″ type=”Controller2″ message-listener message=”Message” function=”DoTarfu” /controller

  6. |

    Thank you Joe for the clarifications. I have updated the FAQ accordingly. I really appreciate your valuable contributions to the ColdFusion community.

  7. |

    I am trying to figure out how to use -name=”eventValue”- in the ModelGlue.xml to switch between ‘. I am not a fusebox guru but I frequently use the param fuseaction as a way to control my layouts. Can you point me to an example that shows how to use the ‘event-value’ to switch between ? Thanks

  8. |

    Tim, I am not sure I understand what you’re trying to ask. The resources I have listed above are a great way to learn more about Model-Glue.

  9. |

    […] via: […]

  10. |

    Hey Eddie, very nice work and right on the money across the board! Your article should be linked from the ModelGlue site as an unofficial FAQ, imho!

  11. |

    […] Once finished you can also use Eddie Awad’s MG FAQ as a reference. […]

  12. |

    Thanks for putting up this post! I was just checking out the MG mailing list but the built in search functionality seems to be lacking, so this is greast.

  13. |

    […] Eddie Awad’s Model Glue FAQ […]

  14. |

    nice move with referrer grubber – is it plugin ?

  15. |

    Slava, I believe you are asking for this wordpress plugin.