So you want to create a ModelGlue:Unity application? ( Part 10 )
Sean Corfield pointed out that using ColdSpring to make instance (throwaway) components is quite a heavyweight approach for a simple form bean. He is, of course, correct. Our ContactFormBean is currently created by ColdSpring. In this series, we will add a factory object that will make our instance beans for us. The factory itself will be configured through ColdSpring as well as the configuration for our objects.
This is a very simple factory. It has three methods, GetConfig, SetConfig and getBean. In turn:
- getConfig() returns a struct with keys = objectnames, and values = paths
- setConfig() provides an interface for ColdSpring to set the configuration struct.
- getBean() gets the path for a specific object from the configuration struct and returns a created object.
<!--- Author: dwilson Date: 3/14/2007 Usage: I return an instance object --->
<cffunction name="getBean" output="false" access="public" returntype="any" hint="I return an instance object">
<cfargument name="ObjectName" type="string" required="true"/>
<cftry>
<cfreturn createObject( "component", structFind(getConfig(), arguments.ObjectName ) ).init() />
<cfcatch type="any">
<cfthrow message="BAD_OBJECT_CONFIG_IN_INSTANCEFACTORY" detail="You provided [ #arguments.ObjectName # ] and I can't create it. Go check the config." />
</cfcatch>
</cftry>
</cffunction>
<!--- Usage: GetConfig / SetConfig methods for Config value --->
<cffunction name="getConfig" access="public" output="false" returntype="any">
<cfreturn variables.instance.Config />
</cffunction>
<cffunction name="setConfig" access="public" output="false" returntype="void">
<cfargument name="Config" type="any" required="true" />
<cfset variables.instance.Config = arguments.Config />
</cffunction>
</cfcomponent>
To use this instance factory, add the following ColdSpring xml snippet to the ColdSpring.xml file.
<property name="Config">
<map>
<entry key="ContactFormBean"><value>ContactManagerMG.model.ContactFormBean</value></entry>
</map>
</property>
</bean>
Now remove the original ContactFormBean configuration.
Next, open the Controller.cfc file and change each instance (getContactForm, handleContactForm and removeContact) of getModelGlue().getBean("ContactFormBean") to getModelGlue().getBean("InstanceFactory").getBean("ContactFormBean") .
Finally, reinitialize your application and click on the ContactForm tab. You should see your form as before.
A factory might seem like overkill right now, since this is a simple application. However, Factory objects are a good pattern to learn. Our motivation for the factory in this case was to reduce the amount of unnecessary processing incurred by using ColdSpring to make a simple form bean. We could however, expand our factory to take additional parameters and create all sorts of dynamic objects for us.
In a later series, we'll do just that.








I have downloaded the sample contact manager application built using mode-glue
I am currently learning model-glue, I have added the few code for login process based on ray's code in photo gallery, I am able to display the login page . While clicking the login button I am getting an below mentioned error message.
Can you help me to solve this issue? Please dont mistake me for asking some simple and basic questions. I hav
If you need i can send the updated code files
Oops!
Message
The method 'setAppConfig' could not be found in component D:\FuseApps\ContactManagerMG\model\userBean.cfc.
Detail
Check to ensure that the method is defined, and that it is spelled correctly.
Extended Info
Tag Context
D:\FuseApps\coldspring\beans\DefaultXmlBeanFactory.cfc (608)
D:\FuseApps\coldspring\beans\DefaultXmlBeanFactory.cfc (332)
D:\FuseApps\ModelGlue\unity\ioc\ColdSpringAdapter.cfc (63)
D:\FuseApps\ModelGlue\unity\framework\ModelGlue.cfc (131)
D:\FuseApps\ContactManagerMG\controller\Controller.cfc (84)
D:\FuseApps\ModelGlue\unity\listener\Listener.cfc (51)
D:\FuseApps\ModelGlue\unity\eventrequest\MessageBroadcaster.cfc (57)
D:\FuseApps\ModelGlue\unity\framework\ModelGlue.cfc (384)
D:\FuseApps\ModelGlue\unity\framework\ModelGlue.cfc (357)
D:\FuseApps\ModelGlue\unity\framework\ModelGlue.cfc (331)
D:\FuseApps\ModelGlue\unity\framework\ModelGlue.cfc (289)
D:\FuseApps\ModelGlue\unity\ModelGlue.cfm (126)
D:\FuseApps\ContactManagerMG\index.cfm (50)
I would love to help you. It seems as if you didn't leave your email in the comments. Off the cuff, it seems like your userBean.cfc doesn't have a method called setAppConfig.
You may want to have a look at the userBean. My code doesn't include a userBean at the present time so I can't dig into it and verify.
If you leave a comment with your email, i'll do what I can to help.
DW
I've also learned much from these entries!
Thank you, Mr Wilson!
Keep up, ur work!
http://yourstress.info