Jun 9 2006

Model-Glue:Unity "ActionPacks"

Posted by Joe Rinehart at 11:44 AM
13 comments
- Categories: Model-Glue

One critique I've heard about Model-Glue is that there's no easy way to create "modules" of functionality that can be "dropped in" to existing applications.

I mean, wouldn't it be nice to write a forum app, and then just say "add this to my Model-Glue application?" Well, there's a new tag in Model-Glue:Unity that allows just this: <include> as a child of <modelglue>. I've resisted it for a while, but I think that, when used properly, it could be a very nice addition to the framework.

This addition means that any ModelGlue.xml file can other ModelGlue.xml-format files, and that the "child" files can declare their own <controllers> and <event-handlers>.

Additionally, the Model-Glue XML "fragments" can use the <setting> tag to declare additional XML files to load into ColdSpring as well as additional directories to use as view mappings.

Example

This means that I could have a Wiki.xml "fragment" file declaring everything needed for a wiki:

<modelglue>
<config>
<!-- Add the wiki /views dir to the viewmappings -->
<setting name="viewMappings" setting="/mgwiki/views" />
</config>

<controller name="wikiController" type="mgwiki.WikiController">
<message-listener message="wiki.page" function="getPage" />
<!--- other listeners... --->
</controller>

<event-handlers>
<event-handler name="wiki.displayPage">
<broadcasts>
<message name="wiki.page" />
</broadcasts>
<views>
<include name="body" template="dspWikiPage.cfm" />
</views>
<results>
<result do="view.template" />
</results>
</event-handler>

<!--- More event handlers... --->
</event-handlers>
</modelglue>

Then, if I wanted to add Wiki functionality to any other Model-Glue application, I could change its ModelGlue.xml file to include the Wiki fragment:

<modelglue>
<include template="/mgwiki/config/Wiki.xml" />

<!--- Application stuff...--->
</modelglue>

Dangers of Includes

Doing this isn't without a danger: it's quite possible that an include would overwrite an existing event handler or controller. That's the reason I prefixed everything with "wiki" :).

"ActionPacks?"

I'm planning on releasing a few fragments in the publuc "2.0" Unity release that I'll be calling "ActionPacks." One will provide an easy to use, configurable e-mail service. Another will provide role-based and row-level security, user profile management, and user administration interfaces.

Because these "ActionPacks" don't require any change to the framework, and are really just Model-Glue XML fragments, anyone is free to contribute their own to the Model-Glue community. If anyone's interested in developing them, I'd be happy to help out where I can, and for select Action Packs (like maybe a forums app!), adding them to the Model-Glue distro itself.

Comments

Sami Hoda

Sami Hoda wrote on 06/09/06 12:27 PM

Very interesting Joe. The concept of plugging in sub apps is very powerful. It takes the concept of &quot;plugins&quot; to a whole new level! I'm eager to try it out!
Nando

Nando wrote on 06/10/06 2:23 AM

Joe, Hanging out in &quot;Pretend it's magic&quot; land, what about adding a namespace attribute to the include tag, so it eliminates the possibility that events (and hopefully controllers) could step on each other? How doable would that be? Not knowing much about how the framework functions, in my imagination it would mean that when the framework loads an included ActionPack, it would prepend the namespace to the event name, or something like that, and use that event name in the mother app.

The idea would be to eliminate the need for a conscientious programmer to always ensure they name their events uniquely across all applications ever created by anyone, either in the past or in the future. ;-) And provide a framework supported convention for what you seem to be doing already with your &quot;wiki&quot; namespace.
Nathan Strutz

Nathan Strutz wrote on 06/12/06 4:20 PM

Nando,

I agree that a namespace attribute would seem easy, but that would affect more than just what seems obvious. Links, including those internal to your ActionPack, would have to change based on their namespace. And if you change the namespace, you have to change all your links. This would require strict xfa style programming and validation, plus some automation to apply the namespace to them. It's possible, but not easy. Instead, I can see why keeping a manual prefix would be much easier.
Nando

Nando wrote on 06/12/06 7:31 PM

Hmmm ... so it would need a framework mechanism, similar to #myself#, to dynamically handle the namespaces in the links. If it were present in the framework, you wouldn't have to use it. You could still name your links with a manual prefix.

I certainly see your point tho'. But on the other side of the coin, we're looking at a situation where you're going to sometimes have to change all your links anyway. Or weed through them and figure out which to change and which to leave. Event names tend to be not very unique. I'm sure we all use the same ones a lot of the time. That's why i thought it was important to bring this up and see what people thought.
Jason

Jason wrote on 06/19/06 5:42 PM

Joe,

Is this in the beta release of Unity already? or do we have to wait :(

Thanks for your great work!
Jeff Lester

Jeff Lester wrote on 06/19/06 8:30 PM

Okay, I've attempted this but I keep getting errors that state that the include file cannot be found in my specified view directory. I am using the unity style configuration (seperate Reactor, Coldspring, ModelGlue xml) but your example shows to include the view config setting in the ModelGlue xml. Is there something that I'm missing?
Jeff Lester

Jeff Lester wrote on 06/20/06 1:35 AM

Okay, scratch that, I got it working. Make sure you don't have any of the potential duplicate event-handlers or controllers. Also, ensure that your include xmls aren't named ModelGlue.xml as I think that also caused a few problems. All in all, _very_ impressed with this plugin method. I have been able to eliminate hundreds of lines of duplicate code from the sub-app method I was using before. Two thumbs way up Joe!
Paul Peterson

Paul Peterson wrote on 01/18/07 11:10 AM

Hi, Joe.

I'm playing the the emailService actionpack and have a question regarding it's initialization.

In it's ModelGlue.xml there is a OnRequestStart listener that calls &quot;loadEmailService&quot; from EmailController.

In EmailController.cfc there is a loadEmailService function the loads the emailService into the view state.

Where/how does the emailService get init'd?

Is this something that the MG framework does for 'behind' the scenes based on Coldspring bean defs?

thx.

pwp
Paul Peterson

Paul Peterson wrote on 01/18/07 12:15 PM

Please ignore the above questions.

I took the time and read the Coldspring docs: www.coldspringframework.org/docs/

Things now make more sense...

pwp
Paul Peterson

Paul Peterson wrote on 01/18/07 4:02 PM

Joe,

I've created a couple of simple actions packs - those without a /config/coldspring.xml - and have gotten them to work in another mg app.

My question is how do I get the actionpacks' config/coldspring.xml - if it has one - included with the mainapp's config/coldspring.xml?

pwp
Toby Tremayne

Toby Tremayne wrote on 03/29/07 3:32 AM

For anyone else following this up, at the time of posting this comment the example Joe gives above doesn't actually work. If you're using an actionpack and getting the template not found error then it's most likely because the line Joe specified as
&lt;setting name=&quot;viewMappings&quot; setting=&quot;/mgwiki/views&quot; /&gt;

should in fact be

&lt;setting name=&quot;viewMappings&quot; value=&quot;/mgwiki/views&quot; /&gt;

Just a heads up for anyone else beating themselves to death over this :)

Toby
Darren Labrum

Darren Labrum wrote on 05/26/07 4:17 AM

I was just wondering what the status of the model-glue actionpacks idea was. I can't seem to find any other information about this feature in model-glue. Where can we find actionpacks? Are they being actively supported or is this feature on hold for now?

Thank you for your work on the model-glue framework. I've really liked what I have seen so far. Keep up the good work!

Write your comment



(it will not be displayed)