2 Replies Latest reply on Jun 22, 2006 8:38 PM by Douglas Knudsen

    array of CFCs and RemoteObject FB2B3

    Douglas Knudsen
      Ok, having some struggles here with ColdFusion CFCs, related AS VOs,
      and remoteobject.
      Say I have a CFC called Customer.cfc which is bean styled. It has a
      property Addresses which is a array of Address.cfc also bean styled.
      Similarly I have ActionScript VOs setup and registered to map to the
      CFCs. Ok, I build a Flex app that retrieves a Customer object. It
      gets mapped over to AS ok, I can see the array of Address objects and
      see they are typed correctly. Now I call a method via RemoteObject
      called save() passing the Customer object to this method. Bomb! When
      the AS array of objects is passed to CF it loses its type. Below I
      have some code example of what things look like.

      Thoughts?

      Customer.cfc
      <cfcomponent>
      <cfproperty name="customerId" type="numeric" default="0" />
      <cfproperty name="addresses" type="address[]" />

      <cfscript>
      variables.customerId= 0;
      variables.address = ArrayNew(1);
      </cfscript>

      <cffunction name="getCustomerId" output="false" access="public"
      returntype="numeric">
      <cfreturn variables.customerId>
      </cffunction>

      <cffunction name="setCustomerId" output="false" access="public"
      returntype="void">
      <cfargument name="val" required="true">
      <cfset variables.customerId = arguments.val>
      </cffunction>

      <cffunction name="getAddress" output="false" access="public"
      returntype="address[]">
      <cfreturn variables.address >
      </cffunction>

      <cffunction name="setAddress" output="false" access="public" returntype="void">
      <cfargument name="val" required="true" type="address[]" >
      <cfset variables.address = arguments.val>
      </cffunction>

      </cfcomponent>

      address.cfc
      <cfcomponent >
      <cfproperty name="addressId" type="numeric" default="0">
      <cfproperty name="address1" type="string" default="">
      <cfproperty name="city" type="string" default="">
      <cfproperty name="state" type="string" default="">
      <cfproperty name="zip" type="string" default="">

      <cfscript>
      //Initialize the CFC with the default properties values.
      variables.addressId = 0;
      variables.address1 = "";
      variables.city = "";
      variables.state = "";
      variables.zip = "";
      </cfscript>

      <cffunction name="init" output="false" returntype="address">
      <cfreturn this>
      </cffunction>
      <cffunction name="getAddressId" output="false" access="public"
      returntype="any">
      <cfreturn variables.AddressId>
      </cffunction>

      <cffunction name="setAddressId" output="false" access="public"
      returntype="void">
      <cfargument name="val" required="true">
      <cfif (IsNumeric(arguments.val)) OR (arguments.val EQ "")>
      <cfset variables.AddressId = arguments.val>
      <cfelse>
      <cfthrow message="'#arguments.val#' is not a valid numeric"/>
      </cfif>
      </cffunction>

      <cffunction name="getAddress1" output="false" access="public" returntype="any">
      <cfreturn variables.Address1>
      </cffunction>

      <cffunction name="setAddress1" output="false" access="public"
      returntype="void">
      <cfargument name="val" required="true">
      <cfset variables.Address1 = arguments.val>
      </cffunction>

      <cffunction name="getCity" output="false" access="public" returntype="any">
      <cfreturn variables.City>
      </cffunction>

      <cffunction name="setCity" output="false" access="public" returntype="void">
      <cfargument name="val" required="true">
      <cfset variables.City = arguments.val>
      </cffunction>

      <cffunction name="getState" output="false" access="public" returntype="any">
      <cfreturn variables.State>
      </cffunction>

      <cffunction name="setState" output="false" access="public" returntype="void">
      <cfargument name="val" required="true">
      <cfset variables.State = arguments.val>
      </cffunction>

      <cffunction name="getZip" output="false" access="public" returntype="any">
      <cfreturn variables.Zip>
      </cffunction>

      <cffunction name="setZip" output="false" access="public" returntype="void">
      <cfargument name="val" required="true">
      <cfset variables.Zip = arguments.val>
      </cffunction>


      </cfcomponent>

      customer.as
      package customer
      {
      [RemoteClass(alias="customer")]

      [Bindable]
      public dynamic class customer
      {

      public var customerId:Number = 0;
      public var address:Array;

      public function custumer()
      {
      }

      }
      }

      address.as
      package address
      {
      [RemoteClass(alias="address")]

      [Bindable]
      public dynamic class address
      {

      public var addressId:Number = 0;
      public var address1:String = "";
      public var city:String = "";
      public var state:String = "";
      public var zip:String = "";

      public function address()
      {
      }

      }
      }


      --
      Douglas Knudsen
      http://www.cubicleman.com
      this is my signature, like it?
        • 1. Re: array of CFCs and RemoteObject FB2B3
          Douglas Knudsen Level 1
          I put together a sample that shows this not working correctly
          http://www.cubicleman.com/arraytest.zip
          seems the array of address objects does get returned to Flex from CF,
          but the debugger is showing that the elements are plain objects only,
          not a addreess object.

          Seems something is wrong with my returntype on my CFC maybe? What
          should the returntpye be set to when returning a array of CFCs? I am
          using
          returntype="address[]"

          Also, I'm using the debugger in FB. I notice the the parent Customer object is listed in the debug data. Customer.addresses is listed as a array properly, but each element is listed as Object, NOT as Address. ??????

          DK
          DK
          • 2. Re: array of CFCs and RemoteObject FB2B3
            Douglas Knudsen Level 1
            thanks to super Flex man João Fernandes for the solution here. In this example here I would have to add

            import path.to.address;
            public var placeHolderAddreess:path.to.address;
            import path.to.customer;
            public var placeHolderCustomer:path.to.customer;

            Apparently the import is not enough, seemed to be ok in Flex 1.5. As João pointed out, must be a compiler efficiency approach.

            Thanks again João!

            peas

            DK