Archive

Archive for September, 2008

Inheritance between ColdFusion and Flex

September 12th, 2008 Gareth 6 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: , ,