Passing object to a CFC, Flex or CF bug?

I’m not sure who is to blame, but this really smells like a bug to me. I’m getting into the habit of creating an object in Flex if I’m sending a lot of fields to a CFC. It shortens up the RemoteObject call and makes debugging easier because then all the data to be passed is in a single structure.

So I have this harmless looking bit of code. Make an object, figure out the value of some Boolean, and call a method in my RemoteObject.

var deptInfo:Object = new Object();
var newDept:Boolean = chNewDept.selected ? true : false;
deptInfo = {
  DepartmentID : cbEditDept.selectedItem.DepartmentID,
  Department : tiEditDeptName.text,
  Division : cbEditDivision.selectedItem.Division,
  newDept : newDept};
ro.saveDepartment(deptInfo);

Simple enough. The function it’s calling is simple too. Take the data and mangle it with queries and whatever.

<cffunction name="saveDepartment">
  <cfargument name="deptInfo" type="struct" required="true">
  ...
</cffunction>

Cool, let’s run it…

coldfusion.runtime.MissingArgumentException: The parameter DEPTINFO to function saveDepartment is required but was not passed in.

AHH! What? Everything I tried in Flex, that object wasn’t ending up in the arguments scope of the ColdFusion function. I set the access to remote and called the function through the URL, it works fine. I tried a cfinvoke from ColdFusion…

<cfset deptInfo = StructNew()>
<cfset deptInfo["DepartmentID"] = 1>
<cfset deptInfo["Department"] = "testdept">
<cfset deptInfo["Division"] = "testdiv">
<cfset deptInfo["newDept"] = true>
<cfinvoke component="kiosc.cfc.disc" method="saveDepartment" deptInfo="#deptInfo#"/>

And it works fine. So what’s wrong with this running from Flex? I checked with ServiceCapture, that shows the object’s data being passed properly over the wire. I got the bright idea to pass another, dummy, variable along with my structure.

ro.saveDepartment(deptInfo,1);

And that works. So tell me, what the hell. Searching Google came up with nothing, implying no one else is having this problem. I have another application that does this same thing, making an object and passing it to the CFC, and that worked fine. But that one is sending the object and 2 arrays. This one that didn’t work is only passing the object. Is there some bug with only passing a single object to a CFC?

~ by codingmurloc on May 15, 2007.

One Response to “Passing object to a CFC, Flex or CF bug?”

  1. Thanks to Pete on FlexCoders … I’m a doof. If a single object is passed in, CF thinks it’s a structure of the arguments. Less than a week of blogging and I’m making stupid mistakes! Two solutions…

    Solution 1: Change the cfc. Instead of the CFC taking a single argument, have it take the 4 that are in this object.

    Solution 2: Make a wrapper. Put the object of data within another object

    var wrapper:Object = new Object();
    wrapper = {empInfo : empInfo};
    ro.saveEmployee(wrapper);

    Solution is probably the better one. You’d have fewer objects floating around in memory and have a cfargument tag for each thing you’re passing in.

Leave a Reply

You must be logged in to post a comment.