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!

Comments Comments (15) | del.ico.us del.icio.us | Digg It! Digg It! | Linking Blogs Linking Blogs | 10043 Views

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)

  • # Posted By Phil | 1/28/08 12:13 PM

    Just an FYI for others out there...

    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.

  • # Posted By Brian Kotek | 1/28/08 12:16 PM

    Hmm, since I always use FireFox I've never even noticed that the direct links into the LiveDocs might not work in IE. However, rest assured that Flex apps run just fine on IE. :-)

  • # Posted By Brian Kotek | 1/28/08 12:19 PM

    No idea why the comment box wouldn't open for you in IE since I *know* it works. Maybe you have a popup blocker or something that is interfering with JavaScript?

  • # Posted By Tom Chiverton | 1/29/08 9:35 AM

    Now that's handy !
    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.

  • # Posted By James Netherton | 1/29/08 6:20 PM

    Very cool!

    I just gave this a try and it works very nicely. Definately more performant than using CFC instances.

  • # Posted By Gareth | 2/19/08 3:12 PM

    Is this only for CF8? If so, is there a method for doing this on MX7 (without having to do the createobject)?

  • # Posted By Brian Kotek | 2/19/08 5:22 PM

    As far as I know it's CF8 only, but you can try it on CF7 to see if it works.

  • # Posted By James Netherton | 2/19/08 5:43 PM

    It is CF8 only, as I found out to my cost last week when porting my app over to CF7.

  • # Posted By Tom Chiverton | 2/20/08 5:11 AM

    I believe it works on CF7, but is undocumented so you may not want to use it.

  • # Posted By Gareth Arch | 2/25/08 7:04 PM

    nope, officially does not work in CFMX7. I got an e-mail from Adobe confirming. May work with CFMX7 and LiveCycle, but CF8 does it standalone (via the built in Flex data services express)

  • # Posted By Kyle Hayes | 2/27/08 4:06 PM

    Is there a reliable way to use Transfer with my Flex applications?

  • # Posted By Brian | 2/27/08 4:28 PM

    Kyle, Transfer works the same way anything else does on the server when it comes to Flex: you call your remote proxy objects (handcoded or generated by ColdSpring), and those can then call anything on the server side that you need to. You then format the results so that Flex can understand them (as Value Objects or as typed structs) and return them to Flex.

  • # Posted By Kyle Hayes | 2/27/08 5:22 PM

    Oh yes, of course. I'm not sure why I was thinking about it differently ( cause now I feel stupid [lol]). I was reading in the Google Groups about using AOP to convert the query or TransferObject into the typed object for Flex. How do I set this up in my Flex/ColdSpring/Transfer environment?

  • # Posted By Brian | 2/27/08 6:00 PM

    I have a blog entry on this at http://www.briankotek.com/blog/index.cfm/2008/1/7/... but you may have better luck asking on the ColdSpring list since this can get somewhat complicated if you've never used AOP before.

  • # Posted By kocsog | 7/1/08 3:02 PM

    I believe it works on CF7, but is undocumented so you may not want to use it.