Ask a Jedi: Making use of ColdSpring/Model-Glue and Remote Proxies

Dean asks:

I know your big on both Model-Glue and cfajaxproxy, so I thought I would ask for your help using them together. If I have a Model-Glue app that has all of my objects defined and managed using ColdSpring, how would I call one of my service objects using the cfajaxproxy tag? All of the examples I have seen show calling the CFC's directly, but since my service object requires the injection of my DAO and Gateway objects, the direct call would fail. So I am a little stumped as to what to pass to the cfajaxproxy tag.

There are two answers to this (well I'm sure there are more, but two I'll focus on) problem. The simpler way, and the way I've done it in the past, is to not use the CFCs at all. Instead, my AJAX based actions will use normal Model-Glue events. So for example, I may have an event call getBlogEntriesJSON. This event handles broadcasting a message to get the blog entries, and then another method to handle converting the value to JSON. However, I've known for a while that ColdSpring had some support for automatically exposing itself to remote calls so I thought this would be a great opportunity to give it a try.

Another RIAForge update, and some good examples of my mistakes

I had a moment yesterday to take another look at RIAForge and it's ongoing issues. This time I focused on a problem with the project, Project Tracker. For some reason this project would take around 60 seconds to render the home page. Other projects were much faster. As far as I could tell, nothing was special about that project, but everything about it was just horribly slow, almost unusable. I did some digging and finally found a slew of things that I had screwed up. Here they are in no particular order.

A tip concerning Model-Glue and Google AdSense

Here is something I've run into with Model-Glue and AdSense. I'd bet it would also apply to other frameworks and similar advertising engines.

Model-Glue 3 - Custom Event Types - Want that in XML?

After my last post on custom event types in Model-Glue 3, the reaction was pretty much universal. Nice - but why can't we define these guys in XML?

As of about an hour or so ago, Joe checked into the MG3 Subversion repo an update that now allows you to do custom event types in XML, and frankly, it kicks butt. To define a custom event type, you create a new section of your ModelGlue.xml file named event-types. Here is an example:

<event-types>
   <event-type name="templatedPage">
      <after>
         <results>
            <result do="template.main" />
         </results>
      </after>
   </event-type>
</event-types>

In general these follow the same formats as events, but they are separated into a before and after section. You would put broadcasts in the before block. Here is an example Joe created showing a security custom event type:

<event-type name="securedPage">
   <before>
      <broadcasts>
         <message name="doSecurityCheck" />
      </broadcasts>
   </before>
</event-type>

Using the custom event type hasn't changed. You simply provide the name:

<event-handler name="page.index" type="templatedPage">

And of course you can use multiple custom event types:

<event-handler name="page.index" type="securedPage,templatedPage">

Can I get an "Amen" from the Model-Glue crowd?? (Thanks Joe!)

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:

SES Urls in Model-Glue 3

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:

  1. 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.
  2. 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).

More Entries