7 Replies Latest reply on Mar 13, 2009 2:45 PM by jfb00

    Coldfusion CFC's

    jfb00 Level 3
      Hi All,
      I created a CFC using the wizard in the RDS dataview tab "CreateCFC"
      The wizard created two files for my orders table orders.cfc and orderGateway.cfc
      In my app I try to use the cfc to save a record in order, for that I call saveOrders from ordersGateway.cfc file and pass an array with my values but I got an error saying that I called the wrong method.
      Here is the code for ordersGateway.cfc
      <cfcomponent output="false">

      <cffunction name="get" output="false" access="remote">
      <cfargument name="id" required="true" />
      <cfreturn createObject("component", "orders").init(arguments.id)>

      <cffunction name="save" output="false" access="remote">
      <cfargument name="obj" required="true" />
      <cfreturn obj.save() />

      <cffunction name="delete" output="false" access="remote">
      <cfargument name="id" required="true" />
      <cfset var obj = get(arguments.id)>
      <cfset obj.delete()>

      <cffunction name="getAll" output="false" access="remote" returntype="cfcs.orders[]">
      <cfset var qRead="">
      <cfset var obj="">
      <cfset var ret=arrayNew(1)>

      <cfquery name="qRead" datasource="ep">
      select orderid
      from dbo.orders

      <cfloop query="qRead">
      obj = createObject("component", "orders").init(qRead.orderid);
      ArrayAppend(ret, obj);
      <cfreturn ret>

      <cffunction name="getAllAsQuery" output="false" access="remote" returntype="query">
      <cfargument name="fieldlist" default="*" hint="List of columns to be returned in the query.">

      <cfset var qRead="">

      <cfquery name="qRead" datasource="ep">
      select #arguments.fieldList#
      from dbo.orders

      <cfreturn qRead>


      I called the method passing an array argument like this
      <mx:method name="saveOrder" result="saveOrderRO_Handler(event)">
      Where myArray is constructed like:
      myAC.addItem([{orderid:0, orderdate:this.orderdate.text,
      customerid: this.customers_cb.selectedItem.id,
      addressid: this.address_cb.selectedItem.id,
      price: this.price.text, status:1}]);

      Looks like the orders.cfc file is never called.
      Anybody can explain or have some links to share?
      I would like to take advantage of using this wizard cfc's
      Thanks in advance


        • 1. Re: Coldfusion CFC's
          JeffryHouser Level 4
          Most likely the issue is that the Flex client is not finding the CFC, so I'd verify that is not the case first.

          Your MXML code doesn't have a RemoteObject tag; so it is hard to diagnose that.
          • 2. Re: Coldfusion CFC's
            jfb00 Level 3
            Sorry, I did n't copy all the code, but yes it's calling the right cfc.
            <mx:RemoteObject id="my_RO" destination="ColdFusion" source="myDomainFlex.cfcs.ordersGateway">

            Do I have to call the orders.cfc also? or ordersGateway take care that part?

            • 3. Re: Coldfusion CFC's
              JeffryHouser Level 4

              Based on the code [snippets] it looks like your CF code creates an instance of the orders; so you do not need to do so in Flex.

              However, I do not see a saveOrder method in your CF code. I should have noticed that originally. Maybe you need to change to "save"
              • 4. Re: Coldfusion CFC's
                jfb00 Level 3
                Great, I replace the name with saveOrder and now I have a different error:
                [RPC Fault faultString="Unable to invoke CFC - The save method was not found." faultCode="Server.Processing" faultDetail="Either there are no methods with the specified method name and argument types, or the save method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that matched the provided arguments. If this is a Java object and you verified that the method exists, you may need to use the javacast function to reduce ambiguity."]
                Any ideas?

                • 5. Re: Coldfusion CFC's
                  John Hall Level 4
                  Generally, that message is what I get when it can't find the CFC. I don't use the CF gateway because I can't always have control over the CF server on some of the stuff so I call the CFC directly in the web site itself.

                  When I do it that way, it's important (sorry if this is review but just want to make sure you understand) to give the fully qualified path to the cfc in the remote object. So if I've got a website called http://www.myWeb.com and a cfc folder underneath, the remoteObject would have a source of something like

                  <mx:RemoteObject id="my_RO" source="myWeb.cfc.orders" destination="ColdFusion" />

                  Don't know if this provides any help but thought I'd mention it. The other thing that's kind of a pain in the butt to get going but really worth it in the long run is to get the step-through debugger working for CF in eclipse. Then you can go line by line debugging and see what's cooking during the call.
                  • 6. Re: Coldfusion CFC's
                    JeffryHouser Level 4

                    I don't understand the difference between using the CF Remoting Gateway and the approach you describe.


                    I'm not sure what else to tell you. Have you tried using a sniffer, such as ServiceCapture or Charles to see what is going on in the calls back and forth? Have you tried invoking the CFCs from a cfm page to be sure that they work? Have you tried running ColdFusion at the console to see if any errors are cropping up that are not obvious?
                    • 7. Re: Coldfusion CFC's
                      jfb00 Level 3
                      I keep running in circles trying to find out how this cfc's works. It has to be a way to find out from adobe the creation on the cfc wizard in how works... right?
                      I would like to take advantage of this auto code :), in the mean time I will keep writing my code for the cfc's