Flex, ColdFusion – RemoteObject HelloWorld Application

For a while now when I have a new ColdFusion Flex scenario set up and need to do a quick check on connectivity I use the cool app provided by Kyle Quevillon available here. Thing is over time I noticed more and more people hitting the a problem with the basic connectivity of Flex and ColdFusion. Also if tweaks are needed for either the RemoteObject source url or the actual cfc itself, it can become a real pain going back into Flex, retyping in new values, rebuilding and finally uploading to the remote server (if not testing locally obviously).

So I decided to come up with my own small application which overcomes these issues and offers a simple solution for testing Flex and ColdFusion connectivity with little knowledge required to use. Also the app feeds the RemoteObject URL and CFC name so there is no need to have to go back into Flex and recompile, or even amend the app for redistribution to another server, easy!

First up this app tests the flex2gateway simply by allowing the user to type in their domain name with the expected result of a blank page. If that doesn't work we need to stop right there and deal with that issue first (this is not a solutions application). Next the user can enter the directory structure to their cfc i.e. Context Root --> CFC containing directory. They then enter the CFC name they want to hit. This CFC need only contain the following script:

CODE:
  1. <cfcomponent name="HelloWorld">
  2.  
  3.     <cffunction name="makeRemoteCall" access="remote" returnType="string">
  4.         <cfreturn "Hello World!">
  5.     </cffunction>
  6.    
  7. </cfcomponent>

If the remote call is successful we should see a message output detailing the successful URL, a success flag and the returned String from the CFC. Any faults will be displayed in the same window.

demo

Newtriks Flex and ColdFusion Hello World Application

Lastly, all of this is built using PureMVC so if you want to learn more about structuring Flex applications that connect to ColdFusion making remote calls and handling resulting data, viewSource is available and the source files are also attached!

source

** Further note **

The application takes advantage of a alternative method of connecting to ColdFusion from Flex than the standard mxml RemoteObject. I have created a RemoteDelegate class that acts as the portal to ColdFusion stating the method to be called and use the IResponder interface for handling responses to the remote calls. If a Proxy class with an instance of the delegate class is calling multiple methods in the RemoteDelegate, only 2 methods are required in the Proxy class: result and fault. Then a simple switch or if conditional can be used to filter through the remote call responses and handle accordingly. This I found to be (a) a damn site easier (b) reduced the amount of methods I had to define (c) enabled easier scalabilty (d) enabled me to re-use the classes in many other applications with ease!

This entry was posted in Coldfusion, Flex, PureMVC, Remoting and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

4 Comments

  1. Dan
    Posted July 18, 2008 at 4:32 am | Permalink

    Thanks for the code. Can you go in a little more detail about your remote delegates in how it allows you to re-use the classes in other applications. How can this be? You are defining application specific functions in your delegate. How could this be re-used in another application. Thanks!

  2. Posted July 18, 2008 at 8:53 am | Permalink

    Cool, basically I define a method in the delegate like:

    Actionscript:
    1. public function callCFC( method:String ):void
    2. {
    3.     // Call the service
    4.     var token:AsyncToken = ro[method].send();
    5.     // Notify this responder when the service call completes
    6.     token.addResponder( this.responder );
    7. }

    And in a proxy I simple call this method like:

    Actionscript:
    1. callCFC('makeRemoteCall');

    Obviously you can add further arguments to pass if need be, it does get a little tricky when passing value objects as to maintain the logic that will have to be detailed in the delegate accordingly, but as you can see is hardly any leg work at all (see example below), you could always replaye item:ItemVO with item:* and that would enable you to pass any Object through that method.

    Actionscript:
    1. public function callCFC( method:String, item:ItemVO ):void
    2. {
    3.     // Call the service
    4.     var token:AsyncToken = ro[method].send( item );
    5.     // Notify this responder when the service call completes
    6.     token.addResponder( this.responder );
    7. }

  3. MArcio
    Posted February 13, 2009 at 6:43 pm | Permalink

    Why does not work that way

    I added the following code to the file EntryForm.mxml

    initialize="onInitialize();"

    public function onInitialize():void
    {
    sendEvent( CALL_HELLO );
    }

    ???

  4. Posted February 13, 2009 at 7:13 pm | Permalink

    Marcio try popping it in a CreationComplete event instead of initialize.

One Trackback

  1. By Pages tagged "basic" on July 16, 2008 at 12:25 pm

    [...] bookmarks tagged basic Flex, ColdFusion - RemoteObject HelloWorld Applica... saved by 3 others     shppden bookmarked on 07/16/08 | [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • FreeAgent sign-up


  • Recent Posts

  • Categories