A simple approach to Flex ColdFusion integration

A few weeks ago, I decided to challenge myself and start a side project that involves a Flex front end with a ColdFusion backend.  This was not only my first Flex+ColdFusion project, it was my first hands-on experience with ColdFusion!

Like most folks, I created a new Flex project in Flex Builder and selected ColdFusion as the “Server technology” in the New Flex Project dialog box.  This triggered another dialog which prompted me for information about my local installation of ColdFusion.  Afterwards, I was staring at a blank main.mxml file that magically had the ColdFusion connectivity taken care of.  That’s fine, but I’m the type of guy that wants to understand what has been done behind the curtain.  Also, I wondered how I would handle things when I moved my application to a server that was running a different configuration, etc.  Since all of the configuration is “baked in”, I wasn’t sure how I was going to handle it.

I had recently read Christophe Coenraets blog post title, “Externalizing Service Configuration using BlazeDS and LCDS” which addresses the same issue with configuring Flex applications to use BlazeDS or LiveCycle DS.  After reading Christophe’s blog post, I was able to quickly convert my Flex application to integrate with ColdFusion without any special compiler options or any knowledge of my local file structure, and so on.  After a little trial and error, I am now able to create a plain Flex project with the “Application server type” set to None and handle all of the remoting/messaging setup directly in my code.

My application uses simple remoting to call a ColdFusion components (orderManage.cfc).  It also utilizes LCDS messaging so I need two channel sets.

I start with a global variable for each of my channel sets:

   private var messagingChannelSet:ChannelSet;
   private var remotingChannelSet:ChannelSet;

In my MXML, I setup my remote object and my consumer/producer:

   <mx:RemoteObject id="cfsvc" destination="ColdFusion" source="orderManage">
	<mx:method name="makeOrder" result="makeOrderResultHandler(event)" />
	<mx:method name="getOrder"  result="getOrderResultHandler(event)" />

   <mx:Consumer id="chatConsumer" destination="appComm" message="chatListener(event)" />
   <mx:Producer id="chatProducer" destination="appComm" />

In my init(), I setup my channels, add them to the channelset and then setup my consumer and producer:

   remotingChannelSet = new ChannelSet();
   var rChannel:AMFChannel = new AMFChannel("my-cfamf", "http://localhost/flex2gateway");
   cfsvc.channelSet = remotingChannelSet;

   messagingChannelSet = new ChannelSet();
   var mChannel:AMFChannel = new AMFChannel("cf-longpolling-amf", "http://localhost/flex2gateway/amflongpolling");

   chatConsumer.channelSet = messagingChannelSet;
   chatProducer.channelSet = messagingChannelSet;		

   chatConsumer.subtopic = instanceID + ".CHAT";

The rest of the application code continues as normal.   I still need to externalize the URL that is hardwired into my code.  I’ll probably use a technique similar to Christophe’s example.

I can now call functions in my orderManage.cfc component like this:  cfsvc.makeOrder(….), etc.

Today, I found a blog post by Mike Nimer that covers this same topic from a slightly different perspective.  Mike also has some great tips, including how to externalize the context root and other settings.

I’ll blog more about my application as it nears completion.

PS:  This is my first ColdFusion blog post.  I hope my boss, Ben Forta is proud!  😉

~ by Greg on April 17, 2009.

4 Responses to “A simple approach to Flex ColdFusion integration”

  1. I know I’m happy to see more ColdFusion love.

  2. […] greg wilson – coldfusion flex integration http://gregsramblings.com/2009/04/17/a-simple-approach-to-flex-coldfusion-integration/ […]

  3. Hi Greg, not sure if you can answer this or not. I’m pretty much an expert with ColdFusion, but am just about to write my first line of Flex code. So I downloaded the Flash Builder 4 Beta 2, and ColdFusion Builder for CF9. I work in a team environment though, so I don’t have ColdFusion server running on my local box, it’s only on the Dev, Test, Stage and Production servers. So I’m just trying to figure out how the hack do I setup my first Flex project. The reason I’m doing Flex, is because my current project requires some data to be pushed to connected clients in near real-time. So after reading all sorts of stuff about it, looks like BlazeDS is what I need. Which supposedly comes by default with CF9. But do I need to use BlazeDS for everything? I thought I’d only use if for real-time messaging, but then what do I do with all the regular stuff when I need to hit a CFC to get some data?

    Ok, first real question, once I pick ColdFusion as Server Technology do I need to pick BlazeDS or ColdFusion Flash Remoting? And if I pick one, and I stuck with it for the whole project? So then do I have to have a different project for things that do need to use BlazeDS from the ones that don’t?

    Or based on your post, can I just do something manually in code myself and not have to choose any of these options at all?

    Second question, it asks for a default location of a local ColdFusion server, does that mean I will have to install CF on my local box? Is there no way to make this thing work with CF on our Dev server? I don’t want to have to setup all the data sources local, etc.

    And then what’s it about using build-in coldfusoin web server? What’s the web root, I have to browse for it, does that mean that again there is no way to do this with the Dev server?

    Thanks, hope you can answer some of these.

  4. Hi There,

    Like you Greg, i’m trying ColdFusion and I’m really new to this platform.
    I’ve downloaded ColdFusion 9 server, ColdFusion Builder and Flash Builder.
    The server is configured and working well, I made my first data driven project in CF Builder and it worked, so I’m trying to make my first Flashbuilder project with Colfusion as back end, but when I select in Flashbuilder New Project it doesn’t show me the option to create a Coldfusion based project. so my question is: What do I have to do to flashbuilder show me that option???

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: