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
How to access configuration settings in ModelGlue.xml?
To access the configuration settings in ModelGlue.xml (what’s between
How to invoke a mapped event?
To map a result to an event and invoke the event use
How to get a reference to a config bean?
<cfset appConfig = GetModelGlue().GetConfigBean("yourBeanFile.xml")>
appConfig.getSettingName() to fetch the setting value.
How to access message arguments?
How to send data to a view?
To send data to a view use the
<value> tag inside the
<include> tag like this:
<include template="view.cfm" name="body">
<value name="name" value="value" />
You can specify whether or not to overwrite the value if it exists by adding the attribute overwrite=”true” or overwrite=”false” to the
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.
<include template="view1.cfm" name="body" />
<include template="view2.cfm" name="body" append="true" />
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 name = "Controller2" type = "Controller2">
<message-listener message = "Message" function = "DoTarfu">
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:
<argument name="name" value="value" />
You can then read the argument in the corresponding function in your controller like this:
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?
viewState.getValue("name", "default value")
How to check the existence of a view in the view stack?
How to display the content of a previously defined view?