I ran into a weird issue where Flex was sending a Value Object (VO) to ColdFusion. I currently run ColdFusion 9 on a Windows 2008 Server R2 (64-Bit). When I have the code as follows the VO is transferred to CFC remotely without any issues.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <cfcomponent output="false" alias="com.vo.TestVO"> <cfproperty name="test_id" hint="primary key" type="numeric" /> <cfproperty name="test_value" hint="some value" type="string" /> <cfscript> this.test_id = ""; this.test_value = ""; </cfscript> <cffunction name="init" access="public" returntype=com.vo.TestVO"> <cfreturn this /> </cffunction> </cffunction> |
The above value object is sent from Flex to CFC without any issues. However as soon as I put in get and set methods in the VO for some reason I do not receive the VO. See the code below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <cfcomponent output="false" alias="com.vo.TestVO"> <cfproperty name="test_id" hint="primary key" type="numeric" /> <cfproperty name="test_value" hint="some value" type="string" /> <cfscript> this.test_id = ""; this.test_value = ""; </cfscript> <cffunction name="init" access="public" returntype=com.vo.TestVO"> <cfreturn this /> </cffunction> <cffunction name="getTest_id" access="public" output="false" returntype="string"> <cfreturn this.test_id /> </cffunction> <cffunction name="setTest_id" access="public" output="false" returntype="void"> <cfargument name="test_id" type="string" required="true" /> <cfset this.test_id = arguments.test_id /> </cffunction> <cffunction name="getTest_value" access="public" output="false" returntype="string"> <cfreturn this.test_value /> </cffunction> <cffunction name="setTest_value" access="public" output="false" returntype="void"> <cfargument name="test_value" type="string" required="true" /> <cfset this.test_value = arguments.test_value /> </cffunction> </cfcomponent> |
Unfortunately I did not write the Flex code so I’m not sure what’s happening in the Flex application. Here are my questions.
- How does Flex handle the get and set methods from the CFC value objects?
- Is get and set necessary if the value object is only used to transfer data between Flex and CFC?
- What is the purpose of get and set method?
- I see some programmers set it as a variable scope instead of this. Why?
Any help would be much appreciated.