Passing Application scoped variables to ColdSpring within Model Glue
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
<cfset application.settings = structNew() />
<!-- Add our DSN name to the Settings struct -->
<cfset application.settings.dsn = "myDSN" />
<!-- If our bean factory doesn't exist then we create it. You could also check for a url.reinit var as well here -->
<cfif NOT isDefined("application.beanFactory")>
<!-- Our struct to hold the variables we are going to pass to ColdSpring -->
<cfset properties = structNew() />
<!-- Our struct to hold the variables we are going to pass to ColdSpring -->
<cfset properties.dsn = "dsn_reference">
<!-- Create our bean object -->
<cfset application.beanFactory = createObject("component","coldspring.beans.DefaultXmlBeanFactory").init(structNew(), properties)/>
<!-- Pass a fully qualified path to a bean definition xml file -->
<cfset application.beanFactory.loadBeansFromXmlFile(expandPath('/config/beans.xml'), true)/>
</cfif>
In our Beans.xml we need to reference the properties structure by the key.
1174 Views | Posted At : December 6, 2007 5:32 AM | Posted By : Andy Jarrett
Related Categories: ColdFusion, model-glue, ColdSpring, Rough Guide

