Monday, March 13, 2006

Getting CFC/AS Auto-conversion working

This is regarding Flex 2 Beta 1 and CF 7.0.1.

Concept
One of the new features with the ColdFusion Flex Connectivity is going to be the ability to have your value objects automatically converted between CFCs and .as when you move them back and forth.  It should be a very handy tool.  For example, you might create a user object in Flex and populate it with a username and password collected from a login screen.  Your remote object passes it to a cfc that looks up the user, validates any credentials and populates additional properties.  It then gets passed back to Flex (flash) and updates the original object you passed in.  You then can use the new property values in the rest of your flex app.

Problem
There are a few examples floating around that show you how to do this.  Ben Forta has a pretty detailed example on his blog.  I was also able to find an example on the FlexCoders list: http://groups.yahoo.com/group/flexcoders/message/28768

Both of these examples, while being very informative, sort of left me hanging.  The last step is to validate that you have received a typed component back in Flex.  For me, both of these came back appearing as cf typed objects.  However, in flex they were treated as generic objects and would not automatically convert into the corresponding .as object or populate its values.  The part that was difficult to find/notice was that the typed object that cf was returning was all lowercase, whereas up to that point, the component name and some of the directories were in mixed case.

Use of the c:\CFusionMX7\runtime\logs\coldfusion-out.log was instrumental in finding this bug.

Solution
I think this should be classified as a workaround at this point, since we're still working with beta software.  The mixed case issue for properties has been dealt with in CF by supplying metadata with the cfproperty tag.  Now, I think we need a similar approach for the fully qualified component path/type as well.

I was able to make it work by changing all of the component paths and filenames to lowercase.  Not a very elegant solution, but it lets you keep working.

I've posted about this issue in several blogs and mailing lists, but I've never received a response from anybody running into the same issue.

If there is some other issue that I've overlooked (my coding error, installation problem, wrong software versions, etc.), or if there is a solution in the works, please let me know.

2 comments:

  1. I have some example code of this from my "Intro to Flex 2" presentation that I just gave for a ColdFusion User Group:

    http://www.darronschall.com/weblog/archives/000218.cfm

    ReplyDelete
  2. By the way, it's a known bug that the lowercase keys flag isn't respected by ColdFusion. From what I understand, it's been fixed in a forthcoming update. The workaround, for the time being, is to have multiple [RemoteClass]'s defined. One being the "correct" case, and another being all lowercase so that the CFC returned from CF gets mapped correctly.

    ReplyDelete