20.15. Receiving Typed Objects with ColdFusion
Problem
You want to be able to handle typed object parameters (i.e., properties of an object that store data of a custom type) sent to a ColdFusion back end (a CFC function or a CFM page).
Solution
Work with the parameter as an ASObject. Use the
get( ) method to get the values for the
properties, and use the getType( ) method to get
the registered class name.
Discussion
Typed objects are automatically converted to
ASObject datatypes in ColdFusion.
ASObject is a Java class that extends the
java.util.HashMap class (meaning all the
properties and methods of a HashMap will also
work for an ASObject) that also adds the
getType( ) and setType( )
methods. If you are not yet familiar with how to work with Java
objects in ColdFusion, you can read more about this in the ColdFusion
documentation here:
| http://livedocs.macromedia.com/cfmxdocs/Developing_ColdFusion_MX_Applications_with_CFML/Java5.jsp#1134356 |
Here is an example of a snippet of ActionScript code that creates a typed object and sends it to a ColdFusion service function:
function MyClass(a, b) {
this.a = a;
this.b = b;
}
MyClass.prototype.a;
MyClass.prototype.b;
Object.registerClass("MyClass", MyClass);
// Send a new MyClass object to a ColdFusion service function.
myCFService.serviceFunction(myResponseObj, {param: new MyClass("eh", "bee")});Here is an example of a ColdFusion snippet that extracts the values
from properties named a and b
from an ASObject named param and also retrieves the ...
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