Returning Typed Structs vs. CFCs to Flex
An awesome little Flex and CF performance gem popped up on the Transfer list last night. Some of us had been discussing how we return data to Flex from ColdFusion. As I've mentioned before on the blog, I use AOP to translate queries and other data into CFC Value Objects for automatic translation into ActionScript classes. I actually thought this was the only way to get the automatic type conversion.
Well Jon Messer piped up with an alternative technique, and Sean Corfield quickly confirmed that it was an "official" option and not just an undocumented hack! You can actually return an array of structures to Flex. You specify all of the properties as structure keys, but then add a key for "__type__", which specifies the CFC type that you want Flex to "see" the structure as! Full details in, where else, the docs: http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=UseFlexDataService_05.html
End result? For large sets of data, this will definitely be faster than returning arrays of CFC instances. I had never even heard of this option so thanks Jon!




The link that was provided in this article at http://livedocs.adobe.com/coldfusion/8/htmldocs/he... just takes me to the root of the online CF documentation. Then I noticed I was using IE. :( Tried it in FireFox and it took me to the correct page. (A similar thing happened when I tried to Add Comment to this article: the dialog did not appear.) Lesson: Use FireFox when visiting the Adobe & Brian's Blog websites. Conjecture: I hope this is not an early warning sign of how well Flex runs in IE.
If you can return a CFC 'type' without needing that CFC to be a real CFC file on disk, that gets around a lot of problems I was having using AOP to do this translation for Reactor, as now there's no need to make sure all the Reactor VO classes have been generated.
I just gave this a try and it works very nicely. Definately more performant than using CFC instances.