[flexcoders] Flex/Coldfusion connectivity test app
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
RE: [flexcoders] Flex/Coldfusion connectivity test app
This sample app also shows how CFC/AS3 VO mappings (or remote class alias) works. Have fun! Benoit Hediard -Message d'origine- De : flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] De la part de Benoit Hediard Envoyé : mardi 7 février 2006 20:37 À : flexcoders@yahoogroups.com Objet : [flexcoders] Flex/Coldfusion connectivity test app 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