Model-Glue 3 - Example of Formats
Time for yet another quick Model-Glue 3 example. This time I wanted to show off formats. In the past, if you wanted to have multiple views of the same type of data, you had to build multiple events. So for example, one page may display a list of all the starships in your fleet in HTML format. If you wanted the same query in JSON, then you would build another event to handle that request. Model-Glue 3 makes this a heck of a lot simpler. The views XML entity now supports a format attribute. So for example:
Link - SES URLs in Model-Glue 3
Doug Hughes posted a good article today on SES URLs within the new version of Model-Glue:
Please pay attention to what he says about ColdSpring and configuration of the Model-Glue application.
Model-Glue 3 - Example of Custom Event Types
Now that Model-Glue 3 has been announced and available for folks to play with, it's time to start working up some demos so folks can see stuff in action. Joe has included a few demos in the zip, but if I don't play with it myself, I don't learn.
Before I go any further, and yes, I will be repeating this warning a lot, keep in mind the following two points:
- Model-Glue 3 is in Alpha. Everything I talk about here may stop working tomorrow. If it does, I'm going to hunt Joe down and make him rewrite Model-Glue in Pascal.
- Like every new feature, there are "good" ways of using it and "not so good" ways of using it. This is the first time I've done this feature. It may be a stupid example. I may look back in a month and ask - what was I drinking.
So with the above in mind, let's dig in.
Running Model-Glue 3 on a box with Model-Glue 2
Just a quick tip. If your box is setup to run Model-Glue2 already, you probably have a ColdFusion mapping set up for ModelGlue that points to the V2 framework. If you want to play with V3 but not mess up your V2 sites (not to imply Joe is anything less than perfect), then consider this simple tip.
Make a new instance of the application template, then open up Application.cfc and add this:
<cfset this.mappings["/ModelGlue"] = "/Users/ray/Documents/workspace/ModelGlue3/trunk/ModelGlue/">
Of course you would edit the path to point to the right folder. This will overrule the ColdFusion Admin's mapping and use a model specific to the application. Of course, this requires ColdFusion 8.
Ask a Jedi: Multiple templates and Model-Glue
Shimju asks:
In a model-glue app, suppose I have 3 templates files - templateA, templateB and templateC. All are set as private events in model-glue.xml. Now my requirement is I want to select a particular template dynamically based on Arguments.event.AddResult("templateA") which we set on contoller method for the event. Based on this, I want corresponding template should appear for that event. Can you please advice how we can accomplish this.
Model-Glue 3 - The New Frakin' Awesomeness
Before I get started - you can download the Alpha now available.
My notes from Joe's Model-Glue 3 presentation at cfObjective. Please pardon the bad writing here and some text are direct quotes without me using quotes (so basically, all copyright Joe).
Model-Glue 3 Preview
I'm a bit late in posting this, but Joe has done a video preview of Model-Glue 3. The video shows off:
- Code generation for unknown events (which I have a problem with, and posted my concerns on his blog)
- SES urls out of the box
- Notice in the video, in his view, he uses Event, which I think is a great change. It was confusing going from Event to ViewState even though they were basically the same object
Quick RIAForge Update
I just spent five minutes on RIAForge changing the search page to use JSON instead of XML. I know I've said this before, but you got to love the size differences. Before the change, the size of the XML packet downloaded was 152KB. With JSON it's down to 72KB.
For those who may view source - please note that I didn't really touch much else - so the code could be even better probably (using the Paged Data support instead of my manual paging for example).
I've blogged about how I integrate Model-Glue with AJAX before, but here is a quick recap. When I make an event that is meant to serve data up to an Ajax client, I first broadcast my message to get my data:
<message name="GetApprovedProjects">
<argument name="mode" value="short" />
</message>
I then broadcast a generic message:
<message name="ToJSON">
<argument name="viewstatekey" value="projects" />
</message>
My controller code for ToJSON does:
<cffunction name="toJSON" access="public" returnType="void" output="true">
<cfargument name="event" type="any">
<cfset var viewKey = arguments.event.getArgument("viewstatekey")>
<cfset var data = "">
<cfset var json = "">
<cfif arguments.event.valueExists(viewkey)>
<cfset data = arguments.event.getValue(viewkey)>
<cfset json = serializeJSON(data,true)>
</cfif>
<cfset arguments.event.setValue("json", json)>
</cffunction>
So in case that isn't obvious - what it means is I can broadcast any message and just pass the results to a generic JSON converter. (The view just dumps out the JSON string.)
Model-Glue Cookbook
Todd Sharp has launched a new site, the Model-Glue Cookbook. As you can guess, this is a site to help you find solutions to common Model-Glue problems. It doesn't have content as of yet, but you can submit content now!
List of Model-Glue sites launched
Many, many moons ago I asked folks to send me their list of sites using Model-Glue.com. I finally got the dang thing updated and posted to Model-Glue.com. You can see the current list here.

