Flex: Objects are like Structures. Kinda. (Part II)
Last night I started documenting my journey of learning Flex, focusing on my use of the built-in Object datatype and some issues that I faced in that respect.
There was one other aspect of this that I meant to touch on. To recap, I was passing a single Object to a ColdFusion CFC method. In my little ColdFusion brain, I thought of this as being not unlike a structure. So, I expected the method to receive a single argument much like a struct with multiple keys.
Let’s say my ActionScript function looked like this:
var args:Object = new Object(); args.stateCode = "CA"; args.zipCode = "94583"; args.territory = 3; // call the remote object method ro_Customers.getFilteredCustomers(args);
I created an Object, populated it with 3 variables (keys), and passed it as an argument to the getFilteredCustomers() method in my remote object (CFC). Originally, my CFC looked like this:
<cffunction name="getFilteredCustomers" returntype="query" access="remote"> <cfargument name="filterCriteria" type="struct" required="true" /> ...
I assumed that my args Object would be able to be referenced as a structure in the CFC. It’s a single variable with key/value pairs just like a struct. But when i tried to reference #arguments.filterCriteria.stateCode#, I found that the variable didn’t exist.
What actually happens is that the CFC treats each value in the Object as its own argument. Think argumentCollection instead of struct.
The correct code for the CFC’s arguments is:
<cffunction name="getFilteredCustomers" returntype="query" access="remote"> <cfargument name="stateCode" type="string" required="false" /> <cfargument name="zipCode" type="string" required="false" /> <cfargument name="territory" type="number" required="false" /> ...
Aside from explicitly declaring each value in the Object, I set the “required” attribute to false because in this case, not all of the values may be present in the Object. A user might choose to search only on stateCode, or only on zipCode, etc.
| 0 comments

Recent Comments