3 Replies Latest reply on Jul 25, 2007 6:24 AM by bendder7

    Send array to CFC

    Hamzaoglu
      Hi,

      I'm stuck at sending an Array to CFC. I defined the array at mxml as;
      [Bindable]private var questionData:Array;

      And adding new elements;
      questionData[questionData.length] = [{questionTxt:txtQuestion.text, answerTypeID:answerTypeID.selectedItem.data, isActive:isQuestionActive, answerData:answerData}];

      Then I loop through my array and create a from with validating, formating, etc. It works fine, I can test my form perfectly.

      Now I need this data to be send to a CF CFC and written to a table. I'm using the following Flex + CF code to Debug first what I'm recieving but it doesn't work.

      --- FLEX ---
      <mx:WebService id="CSService" wsdl=" http://www.mytestsite.com/ws/cs_service.cfc?wsdl" showBusyCursor="true">
      <mx:operation name="SaveFormData" result="saveFormDataResult(event)">
      <mx:request>
      <argFormData>{questionData}</argFormData>
      </mx:request>
      </mx:operation>
      </mx:WebService>

      --- CFC ---
      <cffunction name="SaveFormData" access="remote" returntype="any" hint="Save CS Form data to database.">
      <cfargument name="argFormData" type="array" required="yes" hint="Form data is required">
      <cfmail from="info@mytestsite.com" to="omer@hamzaoglu.com" subject="DEBUG]" type="html">
      <cfdump var="#arguments#">
      </cfmail>
      </cffunction>


      I'm getting this error at swf while testing;
      [RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: https://admin.metroclubkart.com/webservice/cs_service.cfc"]. URL: https://admin.metroclubkart.com/webservice/cs_service.cfc"]

      When I change the argument type to string;
      <cfargument name="argFormData" type="string" required="yes" hint="Form data is required">
      I'm recieving the debug email as [object][object]

      I'm probably not able to send my questionData as Array. Searched forums and other sites but couldn't find a usuable information. Any help is appriciated.

      Thanks in advance.
        • 1. Re: Send array to CFC
          bendder7
          Hello Hamzaoglu,

          I am in the same predicament... any replies or suggestions?

          Thanks, BEN
          • 2. Re: Send array to CFC
            Hamzaoglu Level 1
            Hi Ben,

            I've actually solved my problem and wanna tell you what I've done wrond, maybe help others also.

            I'm using the this code to add items to array but I'm actually using structure. Here is hotter then ever so I've missed this :)
            answerData[answerCount] = [{answerID:"0", answerTxt:txtAnswerTxt.text, answerPoint:txtPointTxt.text, answerIsActive:isAnswerActive, answerOrderBy:"0"}];

            After adding question and answers to structure I'm using a parser to parse this structure as a visible and controlled form which can check for min length, restrict chars, max len, and so. While I'm parsing I've parsed this structure as an array to use at webservice. Created a new array like [Bindable]private var webServiceData:Array = new Array; and entering data in it while parsing it to screen in my parser function. So whenever a question is entered, a new data entered to my structure --> them my parser works --> parses data as a visible form for user interaction and also entering the data to a new array for webservice.

            I could have change my code to use array for the parser and add question, remove question functions but its easier to use structured arrays and its not a problem to write 4-5 line of code anyway. Also when recieving data from the server I'm using XML and converting to structured array. Structured array are easier to work than array and you don't have to remember which part of array holds which data like question[1][5] but instead you can use question[1].questionID.

            Which way I choose doesn't matter because this part of my application runs for administrators and won't be used so much so I don't have a performance concern. But according to your application you may need another solution for performance. This solution works great for me so far.

            Best regards.
            • 3. Re: Send array to CFC
              bendder7 Level 1
              Thanks Hamzaoglu this was a great help. What you have described makes perfect sense. I will have to see about the performance, but going to 8 when it arrives might take care of that as well. Thank you for taking the time to help me out. Keep cool.