You have 2 solutions for your options below.  

 

OPTION 1:

If you're not using Data Services, you're safe defining ambiguous Value
Objects in the client, and register them against a "generic" CFC on the
server, i.e.:

 

[RemoteClass(alias="com.mycompany.myproject.util.Bean")]

public class UserVO {

 

            public var username:String = "";

            public var email:String = "";

}

 

Bean.cfc:
<cfcomponent></cfcomponent>

 

When you send one or an array of UserVO's to coldfusion, you will see
them basically as "simple structs", with username and email fields.

 

Now you just need to write some code so that you can return queries from
your CFC's, inspect the results and create ArrayCollections of UserVO's.

 

OPTION 2:



The other option is to define the remote class specifically:

 

[RemoteClass(alias="com.mycompany.myproject.model.UserVO")]

public class UserVO {

            public var username:String = "";

            public var email:String = "";

}

 

UserVO.cfc:

<cfcomponent>

            <cfproperty name="username" type="string" default="">

            <cfproperty name="email" type="string" default="">

 

            <cfscript>

                        this.username = "";

                        this.email = "";

            </cfscript>

</cfcomponent>


UserHome.cfc:

<cfcomponent>

            ...

            <cffunction name="findAll"
returntype="com.mycompany.myproject.model.UserVO[]">

                        <cfquery name="myFinder" ...></cfquery>

                        

                        <cfreturn convert(myFinder,
"com.mycompany.myproject.model.UserVO")>

            </cffunction>

            ...

 

            <cffunction name="convert">

                        <cfargument name="source" type="query">

                        <cfargument name="type" type="string">

                        

                        <cfset a = arraynew(1)>

                        

                        <cfloop query="source">

                                    <cfobject name="o"
component="#type#">

 

                                    <cfloop list="#source.columnList#"
index="i">

                                                <cfset o[i] =
source[i][currentRow]>

                                    </cfloop>

                                    

                                    <cfset arrayappend(a, o)>

                        </cfloop>

                        

                        <cfreturn a>

            </cffunction>

</cfcomponent>

 

This will automatically convert the data for you in Flex

 

Jay Proulx

[EMAIL PROTECTED]

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of ajudah987
Sent: February 19, 2007 4:02 PM
To: [email protected]
Subject: [flexcoders] Cold Fusion/Cairngorm VO advice

 

I am new to Cairngorm and Flex. Looking over the store example and 
several others and they all seem to use Value Objects to pass and 
define the data on the client. I have a lot of data and structures to 
return to flex in my application. 

1.Should i avoid returning data to Cairngorm via cfc queries and return 
all my data on the server via defined VO's? Does this make sense for 
simple data exchanges?

2.In Cairngorm what is the best way to pass a complex structure into 
the app? For example I have products which belong to product owners 
which are mapped to entitlements. Should i define these all as VO's 
embedded inside each other?

Thanks in advance for any advice,

AJ

 

Reply via email to