2006.12.13...5:35 pm

Flex Problem: Flex to CF remote object call, no result and no fault event returned

Jump to Comments

This problem manifests itself as a call to a method of a remote object (CFC method) where the CFC method actually does process correctly but returns neither a result nor a fault to flex. In this example, we make a call to the IDMethod on a CFC named myDatabaseGateway. However, Flex neither executes the result function nor the fault function.
Here is the code…

THE FLEX REMOTE OBJECT DEFINITION
<code>
<mx:RemoteObject
id=”"myRemoteObject”"
showBusyCursor=”"true”"
destination=”"ColdFusion”"
source=”"myProgram.library.myDatabaseGateway”" fault=”"myDB_fault(event)”">
<mx:method name=”"theIdMethod”" result=”"myIdMethod_result(event)”" />
</mx:RemoteObject>
</code>

THE FLEX ACTION SCRIPT METHODS
<code>
private function myDB_fault(event:FaultEvent):void
{Alert.show(ObjectUtil.toString(event.fault) ); }

private function myIdMethod_result(event:ResultEvent):void
{Alert.show(event.result.ID);}
</code>

THE COLD FUSION METHOD
<code>
<cffunction name=”"theIDMethod “” output=”"false”" access=”"remote”">
<cfreturn 42>
</cffunction>
</code>

On the surface all seems fine when you run this the code on the server does run however neither result nor the fault function in flex is called. The solution to the problem is to fix the method call line in the RemoteObject.
//The line…
<code>
<mx:method name=”"theIdMethod”" result=”"myIdMethod_result(event)”" />
</code>
//should be…
<code>
<mx:method name=”"theIDMethod”" result=”"myIdMethod_result(event)”" />
</code>

The reason that this strange behavior occurs is because while Flex is case sensitive, ColdFusion is case INsensitive. This means that when Flex makes the call to ColdFusion to run, “”theIdMethod”" ColdFusion matches that to “”theIDMethod”" found in the CFC, since from the ColdFusion point of view the method does exist, no fault event is thrown back to Flex. Now when CF is done running the “”theIDMethod”" it returns the result back to Flex now since Flex is case sensitive it tries to find the result event handler for “”theIDMethod”" which it cannot find since it is not defined in the remote object because in the mind of Flex “”theIDMethod”" does not match “”theIdMethod”" Basically, because neither a fault event nor a result event for “”theIdMethod”" was returned Flex just ignores the result event returned and throws it away.

1 Comment


Leave a Reply