Thursday, January 26, 2006

Is cfproperty necessary for the Flex2 CFAdpater?

At the very top of the of the User.cfc in the UserManager sample application, I notice the there is a note that says:

In order for this CFC object to map correctly to an actionscript class, we must define each public property and the type, which maps to the public properties of the actionscript class.

It's followed by a cfproperty tag for each public property in the user object. It has been my experience that cfproperty does pretty much nothing unless you are trying to define a hash-map in a web service. Has this changed with respect to the CFAdapter? If I comment out the tags, the application appears to still work (although I seem to have some issues with caching sometimes).


I have posted this entry in Labs as well.

6 comments:

  1. cfproperty adds metadata. The Flex CF adapter uses that metadata to determine how to map CF/AS data types. Therefore cfproperty is necessary to use the Flex CF adapter.

    Sean Corfield,

    ReplyDelete
  2. Ok, that could come in handy. Strange that is still seemed to work without it. Of course they are just simple strings, so maybe throwing an array in there would cause some fits without the metadata.

    That's good to know. There really isn't much to work with in terms of documentation for the CF adapter yet.

    Thanks.

    ReplyDelete
  3. As an additional follow-up, check out Ben Forta's Phone Selector sample application to see how the new ColdFusion/Flex Connectivity makes use of the cfproperty tag.

    ReplyDelete
  4. Strange that is still seemed to work without it.

    I think it was stated in docs that without cfproperty tags it will pass your CFC as plain object, and can't do one-to-one mapping of AS3 class and CFC. So if type information is important to your app then better use cfproperty.

    ReplyDelete
  5. it is required, for cfc value objects and will be more so in the next beta. So start using it now.

    Since Flex is case/type sensitive, and CF is not we need a way to set these and to force a contract between CF and flash.

    So when you pass a CFC we are only going to pass the cfproperty defined properties (instead of everything in "this" scope). And we will use a get/set method if it exists. Plus, because cfproperty tells us the name and type we will set the property case to match the name and we will try to convert the value to the type set in cfproperty.

    This allows you to set a contract between your CFC and Matching AS class - so you can pass Value Objects back and forth. And your app won't suddenly break if someone uses dot notation instead of bracket notation. Or adds a "this" scope property accidently.

    hth,
    ---nim

    ReplyDelete
  6. Very enlightening.

    Thanks Mike.

    ReplyDelete