Some Tips on Using ColdSpring Remoting
In the normal scenario, I might name my actual ColdSpring factory something like application.factory or application.coldspring. This seems to cause an error when using the auto-remoting feature saying something like:
"Sorry, a ColdSpring BeanFactory named was not found in scope. Please make sure your bean factory is properly loaded. Perhapse your main application is not running?"
After a little digging, you will find that it is calling the getDefaultFactory() method which looks for a factory name of "coldspring.beanfactory.root". I thought you might be able to change this by adding it to the default properties structure you pass into ColdSpring, but it this was possible, I could not get it working.
NOTE: Brian Kotek refers me to a better, though apparently undocumented, solution to this problem. See the comments below.
In the end, you have two solutions. The first, which I first saw here, is as to simply use the default name:
<cfset application["coldspring.beanfactory.root"]= createObject("component","coldspring.beans.DefaultXmlBeanFactory").init(defaultProperties=props)/>
<cfset application["coldspring.beanfactory.root"].loadBeansFromXmlFile(expandPath("/csFlex/config/services.xml"),true)/>
<cfset consoleService = application["coldspring.beanfactory.root"].getBean("consoleService_remote") />
<cfset consoleService = application.factory.getBean("consoleService_remote") />
The second, and the one I prefer, is to use your usual name, but create the remote proxy "manually" using the RemoteFactoryBean API like so:
<cfset application.factory= createObject("component","coldspring.beans.DefaultXmlBeanFactory").init(defaultProperties=props)/>
<cfset application.factory.loadBeansFromXmlFile(expandPath("/csFlex/config/services.xml"),true)/>
<cfset consoleService = application.factory.getBean("&consoleService_remote") />
<cfset consoleService.setBeanFactoryName("factory") />
<cfset consoleService.createRemoteProxy() />
ColdSpring Remoting and ColdFusion 8 Beta
So, you have the prior issue all fixed and everything should work perfectly right? Well, not if you are running the ColdFusion 8 beta. Apparently, a change in ColdFusion 8 has made it so that when a CFC method has a returntype of "any", Flex 2 will completely choke on it returning you something like this:
ArgumentError: Error #2004: One of the parameters is invalid.
at flash.utils::ObjectInput/readObject()
at mx.collections::ArrayList/readExternal()
at mx.collections::ArrayCollection/readExternal()
After searching around, it appears this was discussed on the ColdSpring list and also by Paul Hastings. On Paul's blog, Tom Jordahl notes that this will be fixed in the final release, which is good to hear. Still, it is important to note before you go pulling your hair out trying to get this to work.
Well, I am Stuck
I had hoped to get a sample together to show everyone how you could use my generator and ColdSpring to quickly build a Flex application, but since I am running only 8 locally, this might have to wait until this bug is fixed or I switch back to 7 (which I just might do - yes, I know you can run both but I don't want to spend so much time on a temporary solution).
Yes, the bug with returntype="any" will be fixed in the final release of CF8.
@David, glad it helped.
So, I guess they didn't "fix" it for the release. Maybe it's nothing to be fixed... returntype of "any" is rather vague.

