To get a typed object on the Flex side, there is nothing specific to do, you
only need to correctly define :
- in the CFC VO , all the <cfproperty>,
Ex. : <cfproperty name="someString" type="String" />
- in the service CFC <cffunction>, the correct returnType,
Ex. : returntype="com.mycompany.myapp.model.TestVO"
- in the AS3 VO, the alias metadata,
Ex. : [RemoteClass(alias="com.mycompany.myapp.model.TestVO")]
- in the AS3 VO, all the public var properties
Ex. : public var someString:String;

You might also check 2 things, to see what's going on :
- on the ColdFusion server side, check the CF Adapter logs in
CFusionMX7/runtime/logs/coldfusion-out.log,
- on the Flex client side, install ServiceCapture,
http://kevinlangdon.com/serviceCapture/, you will see if the returned
objects are correctly typed.

Benoit Hediard

-----Message d'origine-----
De : flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] De la
part de anopres
Envoyé : jeudi 2 mars 2006 05:42
À : flexcoders@yahoogroups.com
Objet : [flexcoders] Re: Flex/Coldfusion connectivity test app

How do you use the typed object that cf returns?  All I seemt to get is a
generic object on the Flex side.  Do you have to run through a bunch of set
functions to move the properties returned into a pre-existing .as typed
object?

Sorry for the noob question, but this one has been bugging me for a while.

--- In flexcoders@yahoogroups.com, "Benoit Hediard" <[EMAIL PROTECTED]> wrote:
>
> Since some people seems to have issues to use the Flex/ColdFusion 
> connectivity, here is a sample app to test your connectivity.
> 
> ------------------------
> ColdFusion / Server side
> ------------------------
> 
> Save the following value object CFC in 
> {wwwroot}/com/mycompany/myapp/model/TestVO.cfc
> <cfcomponent>
> 
> <cfproperty name="someString" type="String" /> <cfproperty 
> name="someNumber" type="Numeric" />
> 
> <cffunction name="init" returntype="com.mycompany.myapp.model.TestVO">
>       <cfscript>
>       this.someString = "test";
>       this.someNumber = 0;
>       </cfscript>
>       <cfreturn this />
> </cffunction>
> 
> </cfcomponent>
> 
> Save the following remote service CFC in 
> {wwwroot}/com/mycompany/myapp/service/TestService.cfc
> <cfcomponent>
> 
> <cffunction name="getArray" access="remote" returntype="Array">
>       <cfscript>
>       var data = arrayNew(1);
>       arrayAppend(data, createObject("component", 
> "com.mycompany.myapp.model.TestVO").init());
>       arrayAppend(data, createObject("component", 
> "com.mycompany.myapp.model.TestVO").init());
>       </cfscript>
>       <cfreturn data />
> </cffunction>
> 
> <cffunction name="getStruct" access="remote" returntype="Struct">
>       <cfscript>
>       var data = structNew();
>       data.firstData = createObject("component", 
> "com.mycompany.myapp.model.TestVO").init();
>       data.secondData = createObject("component", 
> "com.mycompany.myapp.model.TestVO").init();
>       </cfscript>
>       <cfreturn data />
> </cffunction>
> 
> <cffunction name="receiveAndReturnVO" access="remote"
> returntype="com.mycompany.myapp.model.TestVO">
>       <cfargument name="vo" type="com.mycompany.myapp.model.TestVO">
>       <cfreturn arguments.vo>
> </cffunction>
> 
> </cfcomponent>
> 
> ------------------
> Flex / Client side
> ------------------
> 
> Save the following value object in {some test 
> project}/com/mycompany/myapp/model/TestVO.as
> package com.mycompany.myapp.model {
> 
>       [Bindable]
>       [RemoteClass(alias="com.mycompany.myapp.model.TestVO")]
>       
>       public class TestVO {
>               
>               public var someString:String;
>               public var someNumber:int;
>               
>               public function TestVO() {
>                       someString = "";
>                       someNumber = 0;
>               }
> 
>       }
>       
> }
> 
> Save the following test application in Flex Builder 2 {some test 
> project}/TestConnectivity.mxml <?xml version="1.0" encoding="utf-8"?> 
> <mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml";
xmlns="*">
>       
>       <mx:RemoteObject id="testService"
>               destination="ColdFusion"
>               result="onResult(event)"
>               source="com.mycompany.myapp.service.TestService"  />
>       
>       <mx:Script>
>               <![CDATA[
>                       import com.mycompany.myapp.model.TestVO;
>                       import mx.controls.Alert;
>                       import mx.rpc.events.ResultEvent;
>                       import mx.utils.ObjectUtil;
>                       
>                       private function onResult(event:ResultEvent){
>
Alert.show(ObjectUtil.toString(event.result));
>                       }
>               ]]>
>       </mx:Script>
>       
>       <mx:Button label="getArray" click="testService.getArray()" />
> 
>       <mx:Button label="getStruct" click="testService.getStruct()" />
>       <!-- BUGS : display (null) value instead of objects, but objects are

> correctly returned... -->
>       
>       <mx:Button label="receiveAndReturnVO"
> click="testService.receiveAndReturnVO(new TestVO())" />
>       
> </mx:Application>
> 
> Compile and run TestConnectivity.mxml (do not forget to set the 
> compile argument to take into account your flex/coldfusion service 
> definition,
> "flex-enterprise-services.xml")
> 
> It should work, if your ColdFusion server is correctly configured
with the
> Flex/ColdFusion connectivity add-on.
> You can also check the adapter logs in 
> {CFusionMX7}/runtime/logs/coldfusion-out.log, very nice to see if
the typed
> objects are correctly received or sent by the ColdFusion adapter.
> 
> ----
> BUGS
> ----
> 
> We have faced several bugs with the Flex/ColdFusion connectivity.
> 
> 1. In the above sample app, getStruct() display (null) object in the
Flex
> app, but objects are correctly returned... Strange.
> 
> 2. Sometimes, the AS -> CFC does not map the full type correctly.
> Example : the CFC might receive "TestVO" instead of 
> "com.mycompany.myapp.model.TestVO", so the CFC argument type
validation will
> fail and you will get an error...
> The current workaround is to remove typed object validation in remote 
> service CFCs.
> 
> 3. You might have to add UPPERCASE setter functions for CFC -> AS 
> translation to work correctly.
> We don't know yet when it is necessary... But sometimes it does!
>       
> Example in TestVO.as :
>       public function set SOMESTRING(value:String):void {
>               this.someString = value;
>       }
>               
>       public function set SOMENUMBER(someNumber:int):void {
>               this.someNumber = someNumber;
>       }
> 
> ---------------------------
> COLDFUSION WITH CAIRNGORM 2
> ---------------------------
> 
> In order to use your service CFCs in a cairngorm application, you
just need
> to add the RemoteObject definition in your ServiceLocator definition
file.
> 
> Hope this helps!
> 
> Benoit Hediard
>






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links



 







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to