开发者

Coldfusion returning typed objects / AMF remoting

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 work开发者_JAVA技巧s 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,


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.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜