The amazing adventures of Doug Hughes

Over the weekend there was a chain of messages on the Model-Glue list about how to get SES Urls working in Model-Glue 3. This is actually quite simple, but the best technique is not immediately apparent. Respondents on the mailing list had it pretty much right but missed an important capability of Model-Glue, which is enabled by the use of ColdSpring.

First off, Model-Glue 3 introduces the concept of a UrlManager. Most people will probably never have to deal with this component, but, behind the scenes this is what essentially populates the event with values from the URL and form scopes.

If you were to dig into the Model-Glue 3 core ColdSpring configuration file you would find a bean with an id of “modelglue.UrlManager” which is of type “ModelGlue.gesture.eventrequest.url.UrlManager.” If you were to look under the /ModelGlue/gesture/eventrequest/url directory you would find two files, UrlManager.cfc, which is the default URL Manager and SesUrlManager.cfc, which we are not configured to use.

The SesUrlManager.cfc is the URL manager you can use with SES Urls. This component knows how to parse urls with this format:

/index.cfm/variable1/value1/variable2/value2&lt;/p&gt;

So, the question then becomes, how do I use the SesUrlManager instead of the standard UrlManager? Easy, just update Model-Glue’s configuration. There are two ways to do this.
The first and most obvious way is to edit Model-Glue’s core configuration file and change the “modelglue.UrlManager” bean to “ModelGlue.gesture.eventrequest.url.SesUrlManager.” However, this introduces a problem. Namely, every application which uses the instance of Model-Glue you edited will now be using the SesUrlManager, which you may not want.

The second and not-so-obvious way to do this is to simply define the “modelglue.UrlManager” bean into your application’s ColdSpring.xml file. Behind the scenes, when Model-Glue is loaded, in the /modelglue/modelglue.cfm file included by your index.cfm, the framework creates a ColdSpring bean factory and loads beans from the core Model-Glue configuration file. Then, it loads all the beans from your ColdSpring configuration file. Any beans in your ColdSpring configuration that already exist in ColdSpring are overwritten by your configuration.

So, by placing the “modelglue.UrlManager” into your configuration file you’re non-destructively overriding how the Model-Glue framework works. This is, quite frankly, my favorite feature of the framework. You can apply this same technique to any ColdSpring-configured Model-Glue object. I actually wrote a blog entry on this a while back: “Extending Model-Glue via ColdSpring.” I’ll be talking on this and other Advanced Model-Glue topics at both WebManiacs and CFUnited!

Related

Comments on: "SES Urls in Model-Glue 3" (2)

Thanks Doug for sharing this. Couple of days before I pointed Ray as SES URL feature didn’t worked for me by default while I tested MG 3.0. I thought It was a bug as MG3 is in ALpha. As per you suggested I used the second way by defining the URL manager bean in my CS.XML file as

Which throws the error: Model-Glue: There is no known event handler for “buildings.view&buildingId=77”.
It works when I manually change the URL to the expected SES format but why might it behave like that?