20.12. Passing Complex Parameters to ColdFusion Component Methods
Problem
You want to pass an object parameter to a ColdFusion Component (CFC) method using Flash Remoting.
Solution
Pass the value as a named parameter.
Discussion
ColdFusion automatically attempts to convert object parameters into named parameters (see Recipe 20.11). This is problematic if you want to pass an ActionScript object to a CFC method as a parameter. Consider the following example:
<!--- A sample CFC method definition ---> <cffunction name="insertCatalogItem" access="remote"> <cfargument name="catalogItem" type="struct"> <!--- rest of method body ---> <cffunction> // The corresponding ActionScript snippet . . . // Create an item object withname,price, anddescriptionproperties. item = new Object( ); item.name = "Widget"; item.price = 9.99; item.description = "Widgets available in green, blue, and gold"; // Call theinsertCatalogItem( )service function and pass it theitemobject. myService.insertCatalogItem(myResponseObject, item);
In the preceding example, we want to pass the item
object from Flash to the CFC method as a parameter that should be
converted into a struct (a complex datatype). However, ColdFusion
attempts to convert the properties of the item
object into named parameters, and it tries to match up the
name, price, and
description properties to corresponding parameters
within the CFC method. This prevents it from successfully passing a
complex parameter, such as an object datatype.
You should ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access