My blog has moved
Please update your bookmarks and feeds for my site.
I now have a Mango Blog at:
http://www.andyjarrett.com/blog
Feed URL: http://feeds.feedburner.com/andyjarrett
Please update your bookmarks and feeds for my site.
I now have a Mango Blog at:
http://www.andyjarrett.com/blog
Feed URL: http://feeds.feedburner.com/andyjarrett
Passing defaultProperties in ColdSpring with Model Glue
Or Using defaultProperties with CS and MG. I couldn't figure out which title would be better.
Basically this is a guide on how to pass variables into ColdSpring. In my case from the Application scope. Recently I've been working on a Model Glue, Transfer, and ColdSpring app and came across a problem which I couldn't find a direct answer to online. The application I'm working is only a small part of the site and has some settings in the Application scope which needs to remain there. Usually I put all my variables in a ColdSpring/Model Glue simpleConfig Bean (using the class ModelGlue.Bean.CommonBeans.SimpleConfig) but this time I needed CS to get the variables from the application scope. This actually isn't too hard as you can pass properties(dynamic variables) into the config.xml e.g.
Here's the code for creating the bean factory. You would find this in onApplicationStart or at the top of your Application.cfm.
Code for Application.cfm/cfc
In our Beans.xml we need to reference the properties structure by the key.
Code for Beans.xml
Now that we have our beans.xml reading dynamic variable how can we pass this to the default ColdSpring.xml that Model Glue uses?
First off when it comes to Model Glue there is already ColdSpring.xml which holds all the config imformation for the application, ORM etc etc. We're not going to touch that so this method is something you can introduce midway through a project. What we are going to do is introduce Beans.xml as the Parent Bean Factory to the child ColdSpring.xml.
Create a SimpleConfig bean from Model Glue (ModelGlue.Bean.CommonBeans.SimpleConfig) and save this in the Beans.xml file. This config bean will hold details for our email server. The values are going to come from the Application scope.
You xml file should look like:
In the Appliacation.cfm add the following code
At this point we have our bean factory stored in application.beanFactory2. We are going to reference this in the index.cfm of MG under the HIERARCHIAL BEAN FACTORY SUPPORT area. Look for the commented out <cfset> which sets the variable ModelGlue_PARENT_BEAN_FACTORY. Uncomment the <cfset> and add the following:
At this point the hard work is done. All that is left is to add a bean that uses the config setting. In my case I have a CFC in a Model folder which accepts the constructor argument "EmailConfig" e.g.
Thats it. From your emailCFC you just need to reference variables.emailConfig.getconfigSetting('emailServer') to the get the server etc.
This post couldn't of been done without the help of http://www.danvega.org/blog/index.cfm/2006/11/25/Passing-Properties-To-ColdSpring and http://groups.google.com/group/model-glue/browse_thread/thread/de628a4fb85c6ebd/ so for futher investigation you can start there.
As the Spry(and any Ajax framework) files aren't the smallest set of files to add to your page you don't want the user to download them if they don't need to. The way I add the Spry files to a display template in Model Glue is per event via a variable defined in the XML controller. For this example I'm going to include the SpryCollapsiblePanel.js file.
1. The first change we make is to your display(also known as Layout) template. At the very top of the template add the following:
Then in the <head> section add the following
2. In the ModelGlue.xml we are going to modify a basic event i.e Before:
After: Using the above event we are going to add a variable to the ViewState
And thats it. When you go to index?event=page.index the <views> will include your file that needs Spry while setting a variable to tell your Layout <result> to add the line of script to the <head>
N.B. There is a deliberate spelling mistake in my MG events due to a small small bug in BlogCFC
I hope this doesn't come across as a moan as its meant to be more of a general question to the community. But with all the main frameworks out there running on XML config files, where are the official DTD's hosted for these? I know there are several around hosted in odd locations (no disrespect), but I was just looking to put together a definitive list of the locations.
I know you can get them via subversion etc but shouldn't/couldn't they be hosted on the respective sites??
Now and then through my work I get asked to create a site with multi-lingual support. In the past I have usually just created a custom tag or UDF. This time, now that I am on A href="http://model-glue.com/">Model Glue: Unity I wanted something that was a little more integrated so I decided to use Ray Camden modified ResourceBundle.cfc. This cfc was actually created by Paul Hastings and you can find more information here.
There are two reasons I am posting this mini guide, first to share and the second is that knowing me I am probably doing something inefficient and by letting the community see it hopefully someone will point out any errors or an easier way to do things :o)
I've zipped up Pauls/Rays ResourceBundle.cfc that comes with BlogCFC and you can download it by clicking here.
Lets's begin:
Thats pretty much covered the basics of setting this up. You'll notice in my last code snippet I use the UK date format style, this won't do if you are creating a multilingual site but there is a utilities package that goes with the resource bundle for this and I hope to cover that in another post.
At the moment I just wait feedback/comment with this approach before I continue.
Thanks to Eclipse making Ant so simple to use I've got it doing a few tasks for me. Well I thought I'd show how simple it is to use. Below is a simple Ant build.xml that I use to copy the ModelGlueAppliactionTemplate files over to a new project. In a nutshell it copies a bunch of files and directories from one location into the location the build.xml was ran from.

Well I'm, writing this on the train home after battling through the ever so friendly people on the london Underground. I'm coming back from the UKCFUG meeting tonight where the topic was Coldspring(CS) and what it does presented my Mark Drew. This is his part 2 speak after the Model Glue(MG) and Reactor(RC) preso the other month.
Though fairly short (about 60/70 minutes) he covered a lot of ground and answered concisely the question of "What the hell does CS do?"
ColdSpring uses Inversion of Control (IOC), dependency injection to wire your CFC's together and is based the Java Spring framework. This still probably hasn't helped you much. To make this simple (maybe to simple) Coldspring runs you init() methods in your components and injects any dependencies. Dependencies can be other other CFC's that are required or even settings. For example a shoppingBasket() is dependant on a taxCalculator(). It doesn't really care about the calculator, but for displaying tax on a product it needs it - its dependant on it. This is where you get Separation of Concern(SOC), component should only needs to know about itself, it doesn't care about its dependencies. So how do you tell shoppingBasket() that it needs taxCalculator(), (as with EVERYTHING nowadays) via a XML config file. Coldspring though can also inject settings as well and you can see this in Model Glue:Unity where's its used to hold(inject) the setting into Reactor and Model Glue.

And this is what Mark broke down over the session. I won't go over the presentation too much as Mark has already hosted his presentation online.
From the last two sessions i've learnt a lot, mainly that Mark Drew can't code when a crowd of people are watching him, but also how MG, RC, and CS all interact, how they all help you separate your code into maintainablem understandable chunks. The other thing i've learnt is to go to your local CFUG when you get a chance. For me its about an hour and 45 minutes+ journey into east London by car/train/tube but its been worth it. I've had the chance to meet some new friends and even managed to get free beer off them - i'll pay ya back next time Alistair. honest ;o)
Also I managed to win my first bit of free swag from a meeting - a cracking Adobe Sim Card Backup keyring. Why its on a keyring i don't know? so far i've never been in a situation where i've need to back my contacts on the move or in an emergency. Either way cheers Nicholas and Adobe.
Plus Mark hinted to look out for CFEclipe 1.3 beta soon, real soon!
I traveled into London again last night to see the Model Glue and Reactor, a winning combination presentation with Mark Drew as the speaker, compere, organiser and the general setting up guy.
The presentation lasted for 2 hours and covered everything from setting up your development environment, to creating the beginnings of a blog app using both frameworks. Mark started with a slide show presentation detailing the frameworks, explaining their relationships to each other and how they are used in the Model-View-Controller (MVC) pattern.
| Model | Reactor |
| View | CFMX |
| Controller | Model Glue |
After this he went through each of the frameworks separately, starting with MG and breaking down the nodes in the modelglue.xml (config file). This then lead onto Reactor, explaining that it is an Object-relationship modeling (ORM) framework. Basically it helps speeds up development but cutting out the need to create SQL statements, DAO's, and Active Records as it does all this on the fly. Using your reactor.xml file you create the links and relationships between you tables and Reactor does the rest.
After the theory we moved into coding which Mark was doing everything on a Mac Book pro - I gotta mentioned it as I bugged him about running anything and everything on it last night as i'm still thinking about getting one . This also meant that cause of the new intel chips he had to set up an extra mapping in the CF administrator which normally wouldn't actually be needed. Mark then went and setup a MG/Reactor environment straight from the .zip files you can download from the sites. There wasnt actually that much new there but it was nice to see it setup from scratch. The next hour or so was used setting up the MG events and listeners, then onto adding Reactor for the database interaction and I think at this point he really showed the power of Reactor. Using a cfc called formutils.cfc (which you gotta release Mark) he generated a form on the fly using the MySQL tables metadata available through Reactor. So if you deleted a field from you "Comment" table, refreshing the form would remove the field. He then proceed to update/insert blog posts and comments all by just setting up the relationships in the reactor.xml.
My write up I don't think has covered half of it really as Mark went into dumping a lot of the objects that MG and Reactor returned to show and explain what is available. Most of the objects in both frameworks have a getAll() method which Mark seemed to be hunting down and utilising everywhere but it did show and display that there are a lot of functions(methods) in these which are helpful but aren't necessarily in the documentation.
Overall it was a great presentation and well worth the trip up. It was also good to not rush off afterward and get a beer over at The Bull afterwards, shame though I had to go to get back to Waterloo before I could hit the vodka.
Joe has released the next update to the 1.x version of Model Glue.
Included amongst the bug fixes are
"This is the end of Model-Glue 1.x development. All new releases will be based on the 2.0 "Unity" core."
So if you do like Bleeding Edge Realease (BER), you can check out the MG BER at svn://clearsoftware.net/clearsoftware.net/ModelGlue.
I think im save is saying Joe is always happy for the testers :o)
UPDATE: By the way the current BER is the 1.1 release. If you want to participate in 2.0 Unity then leave a comment at Joes 2.0 Alpha post
Thanks to Dan Sorensen going through my small multi page demo app I have found a bug. Come the second page of the form there was no check to see if the bean had been created. There is now a check in place so if the bean has not been created it takes you back to the first page of the form.
You can download the app at: http://www.andyjarrett.co.uk/downloads/MG-beans.zip