Home > ColdFusion, Flex, code > Inheritance between ColdFusion and Flex

Inheritance between ColdFusion and Flex

September 12th, 2008 Gareth Leave a comment Go to comments

I ran into a problem today with inheritance in an object in ColdFusion and passing that object back to Flex.  This is the second time I’ve encountered it, and was reminded by an old co-worker of the solution, in one of those “Duh!”, forehead-slapping moments :)

I had created all of my objects in Flex, and then they were mapped by a coworker to the ColdFusion objects on the backend.  He was returning objects back to my Flex components via AMF, but for some reason, the returned object only had the properties for the object that was specifically being called, with none of the properties for the item that it was extending, even though, the properties were being set correctly in ColdFusion.

It turns out that all that was needed was to add the <cfproperty> tags for each of the inherited properties.  Once those were added the previously missing properties were exposed to Flex and passed back correctly.

e.g.
Activity object

<cfcomponent displayname="activity">
<cfproperty name="action" value="" />
<cfproperty name="type" value="" />
</cfcomponent>

Review object

<cfcomponent displayname="review" extends="path.to.cfc.activity">
<cfproperty name="reviewDate" value="" />
</cfcomponent>

If the review object was returned to Flex, it would only pass back “reviewDate”, but none of the properties of the object it is extending. This is due to the review object only having the reviewDate cfproperty. In order to get it to return all properties (from review and activity), you would have to do this:
New and Improved Review object

<cfcomponent displayname="review" extends="path.to.cfc.activity">
<cfproperty name="action" value="" />
<cfproperty name="type" value="" />
<cfproperty name="reviewDate" value="" />
</cfcomponent>

Now you will get all of the review object properties, plus the properties inherited from activity.

Categories: ColdFusion, Flex, code Tags: , ,
  1. September 13th, 2008 at 19:05 | #1

    Hi Gareth!

    I am no ColdFusion programmer, so may sound a bit noobish in this question.

    Just asking out of curiousity, how would you know if it’s extending if you’re declaring the properties?

  2. Gareth
    September 13th, 2008 at 22:24 | #2

    Hey Flashmech,
    No worries about the question. I probably didn’t explain myself as well as I should have :)

    In the ColdFusion component tag, there is an “extends” attribute. This would specify the CFC (i.e. other object) that you are extending. There is going to be some duplication of cfproperty tags between the object it is extending and the object that is inheriting from it, but that appears to be the only way to get Flex to “know” about the properties when it accesses them remotely. In the above example, the ‘extends=”path.to.cfc.activity”‘ is the cfc that it is extending (in this case it would be activity.cfc)

    Hopefully that answers your question, but if not feel free to post again.

  3. September 14th, 2008 at 03:47 | #3

    haha.. actually what I meant is, since you have declare the properties again in the subclass, wouldn’t it work the same way without the “extends” attribute altogether?

  4. Gareth
    September 14th, 2008 at 19:44 | #4

    Ah, OK. I see what you mean. If these were just value Objects then yes, but in our system, these were actually predefined and had other methods and properties already associated with them in the CFC. Plus, by just putting the cfproperties, you lose the relationship between the 2 objects and the business objects (in my company’s case) had a relationship that was shown by Review extending Activity.

  5. September 14th, 2008 at 22:17 | #5

    ah! That’s why I think my question was n00bish~ loL~

    Thanks for answering! I should really try my hands on some backend programming one day. :)

  6. whitemamba
    October 16th, 2008 at 15:57 | #6

    The reason you had to do that (for flashmech’s knowledge) is that in CF, the cfproperty tags are stictly for instance data that is being passed remotely (Web Services, AMF, etc), and to provide additional “metadata” for a CFC. They are altogether useless otherwise and are not really a part of the class/object itself so to speak, so they are not inherited. Did that make sense?

  1. No trackbacks yet.