views:

180

answers:

2

Is the same possible in ColdFusion? Currently I am using .Net/Fluorine to return objects to the client. Whilst in testing I like to pass strings representing the select statement and the custom object I wish to have returned from my service. Fluorine has a class ASObject to which you can set the var 'typeName'; which works great. I am hoping that this is possible in Coldfusion. Does anyone know whether you can set the type of the returned object in a similar way. This is especially helpful with large collections as the flash player will convert them to a local object of the same name thus saving interating over the collection to convert the objects to a particular custom object.

 foreach (DataRow row in ds.Tables[0].Rows)
            {
                ASObject obj = new ASObject();

                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    obj.Add(col.ColumnName, row[col.ColumnName]);
                }
                obj.TypeName = pObjType;
                al.Add(obj);
            }

Many thanks,

+4  A: 

Yes, it works and is built right in so you don't have to use an external server side piece.

ColdFusion Components (CFCs) are the ColdFusion version of an Class.

ColdFusion's Flash/Flex Remoting Gateway will do the automatic conversion of CFCs into ActionScript objects.

Remember that CF is Java based; so the paths and class names are case sensitive. I assume .NET is not like that.

The CFC and ActionScript object should list all properties in the same order. In AS3, you can define them as public variables; in the CFC you should define them using the cfproperty tag. The ActionScript Object should use the RemoteClass metadata tag to specify the absolute location of the CFC. The CFC's cfcomponent tag should specify the alias attribute which is the absolute path location of the CFC Object.

If the CFC method in your service returns an object; the return type on your cffunction tag should be the absolute path to the CFC Object.

I would expect a lot of this is similar to what you've been doing with .NET; just with different syntax. I'm pretty sure you have to enable Flex / Flash Remoting in the CFADmin before any of this will work.

There should be a CF to Flex data type conversion chart somewhere in the CF Docs.

www.Flextras.com
I develop for the ui so i like to decide what my vos look like before I make any decisions as to the services to expose. So that said I have already written the vos in actionscript. So I like to pass the class name to send back as a param to the service I am calling. I currently kind of cast the return object in c# like thus obj.TypeName = pObjType;
Chin
You won't have to do a formal cast from ColdFusion. Just make sure the alias and RemoteClass are set.
www.Flextras.com
Thanks Jeff. That's what I needed to know. Love the show btw.
Chin
Thanks for listening. ;)
www.Flextras.com
+1  A: 

You can also return a struct with a special key called 'type' with the value of the AS class that the properties represent, and Flex will populate those objects.

For example

{
  id=2,
  name=kevin,
  __type__=com.company.user
}

(note that is 'underscore underscore type underscore underscore', the formatting is bein stripped)

David Collie
thanks. I'll check that out.
Chin