The type="Product[]" is a way to make the array returned to be an array of CFC 
objects.  This is a johnny-come-lately syntax addition and I'm not sure where 
it is documented.  Allows you to write code like:

<cffunction name="getProducts" returntype="com.mycompany.model.Product[]">

        <cfset var retArray = ArrayNew(1)/>

        <cfloop from="1" to="10" index="i">
                <cfset 
ArrayAppend(retArray,createObject("component","com.mycompany.model.Product"))/>
        </cfloop>

        <cfreturn retArray/>

</cffunction>

And in your delegate class:

public function result(obj:Object):void
{
        var event:ResultEvent = ResultEvent(obj);
        ModelLocator.getInstance().products = new 
ArrayCollection(ArrayUtil.toArray(event.result));
}

Now your ArrayCollection will contain a collection of AS Product objects - 
directly translated from CFCs. That works and works great and requires that you 
have created a matching AS object to your Product CFC, the how-to of which has 
been written up in numerous places.

What is at issue is specifically the ability to have the ArrayCollection exist 
as a PROPERTY of your ActionScript PARENT object. Like

<cfcomponent name="Catalog" alias="com.mycompany.model.Catalog">
        
        <cfproperty name="catalog__id" type="numeric"/>
        <cfproperty name="catalog_name" type="string"/>
        <cfproperty name="products" type="com.mycompany.model.Products[]"/>

</cfcomponent>

[RemoteClass(alias="com.mycompany.model.Catalog")]

[Bindable]
public class Catalog
{
        import mx.collections.ArrayCollection;

        public function Catalog()
        {

        }

        public var catalog_id:Number;
        public var catalog_name:String;
        public var products:ArrayCollection;
}

If you passing back a Catalog.cfc instance with the products array populated, 
that product array will not be translated over the wire - that's what I'm 
seeing and it just may not be supported yet. What I'm doing currently is to 
populate my Catalog object in two passes - one to get the catalog metadata and 
the other to get the product ArrayCollection. 

Jeff

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Adam 
Dorritie
Sent: Thursday, January 18, 2007 8:22 AM
To: [email protected]
Subject: Re: [flexcoders] Slightly OT - The Limitations of CFMX 7.02


On 1/17/07, Battershall, Jeff <[EMAIL PROTECTED]> wrote:
> I've been using CFMX 7.02's ability translate CFCs to AS objects but  
> have noticed the following limitation:
>
>  If I have an array of objects (like CFCs) in my CFC/AS class def - 
> these  will not translate over the wire and I'm forced to pull over 
> the array  as a separate remoting request.
>
>  Example:
>  Catalog.cfc has an attribute products of type Product.cfc array.  
> <cfproperty name="Products" type="Product[]"/>  Catalog.as has an 
> ArrayCollection of Product objects, i.e., public var  
> Products:ArrayCollection.

I'm confused about the syntax of the <cfproperty> tag you used above. I may be 
wrong, but my understanding is that you would specify that Products is an array 
like this: <cfproperty name="Products" type="array">.  IIRC CF isn't concerned 
about the type of an array's content.  I would also echo João's advice to 
define Products as an Array in your AS class.


--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links



Reply via email to