Important note: Effective with the release of Adobe LiveCycle ES, the Adobe Flex Data Services 2 server product has been rebranded as a Solution Component of LiveCycle ES. This article was written based on Flex Data Services but will likely work as is with LiveCycle Data Services ES. Any articles referring to or using ColdFusion and Flex Data Services are not compatible with LiveCycle Data Services ES. To learn about the new capabilities of LiveCycle Data Services ES, see the tutorials in the LiveCycle Developer Center and read about Adobe LiveCycle Data Services ES.
Adobe Flex 2 has been out for a couple of months now, and lots of ColdFusion customers are discovering that the combination of ColdFusion and Flex allows them to deliver powerful and engaging applications easier than ever before.
One area of confusion appears to be the Adobe Flex server: Adobe Flex Data Services. What is Adobe Flex Data Services? What exactly does Flex Data Services allow you to do that you wouldn't be able to do without it? What does this mean specifically to us ColdFusion developers?
You may want to download and install the following software to follow along with this article:
Important note: Effective with the release of Adobe LiveCycle ES, the Adobe Flex Data Services 2 server product has been rebranded as a Solution Component of LiveCycle ES. This article was written based on Flex Data Services but will likely work as is with LiveCycle Data Services ES. Any articles referring to or using ColdFusion and Flex Data Services are not compatible with LiveCycle Data Services ES. To learn about the new capabilities of LiveCycle Data Services ES, see the tutorials in the LiveCycle Developer Center and read about Adobe LiveCycle Data Services ES.
To get started with ColdFusion and Adobe Flex 2, all you need is ColdFusion MX 7.0.2 (which includes Macromedia Flash Remoting) and Adobe Flex Builder 2 (which contains Adobe Flex 2 SDK). You'll be able to build what are essentially client-server applications, where the client is Flex-generated Flash and the server is ColdFusion. On the server side, you can create ColdFusion components (CFCs) that use CFML and ColdFusion services; and on the client side, you can use MXML and ActionScript to build the Flash user interface.
To understand the relationship better between ColdFusion and Flex (including Flex Data Services), I'll start by clarifying what all of the bits are and what they do:
Flash Remoting is the communication mechanism used to transfer data between a back-end server and a Flash application that runs on a client in Adobe Flash Player. While Flash Player, and thus the Flash applications, can also invoke web services and make HTTP calls directly, Flash Remoting calls generally are preferred because they are more efficient and capable.
To use Flash Remoting, your Flash application—including those created using Flex—must talk to a server with Flash Remoting installed on it. Flash Remoting has been included in ColdFusion for quite a while now, and ColdFusion MX 7.0.2 includes the latest version of Flash Remoting. This is also the version used in Flex 2 applications.
The client application uses Flash Remoting through the <mx:RemoteObject> tag to invoke ColdFusion component (CFC) methods, both retrieving data from ColdFusion and passing data from the Flash client to ColdFusion for processing. To make the integration as simple as possible, data types are preserved and automatically converted to their appropriate equivalent types. If ColdFusion returns a string, Flash receives a string; if ColdFusion returns a query, Flash receives an ArrayCollection, and so on. In fact, even classes can be maintained. Flash Remoting can automatically convert between ActionScript classes and ColdFusion components, allowing these to be passed back and forth efficiently and simply. One of the ColdFusion Flex Builder extensions allows you to right-click an ActionScript file to create the equivalent CFC, and vice-versa.
As I just explained, Flex applications can invoke ColdFusion back-end code. What is key here is that it is the Flash application that has to invoke that back-end code. All back-end interaction is client-triggered, just as it is in web pages. When a user clicks a button, it can trigger a call to ColdFusion, as could a menu selection, a screen change, or any other event. ColdFusion cannot push data down to the Flash client, nor can ColdFusion know anything about what is happening within the client unless the Flash client invokes a ColdFusion method to pass it that information.
So what can you build using this type of interaction? All sorts of things:
<mx:DataGrid>, even allowing users to edit and update the database content. Populate the grid with a call to a CFC method and send changes to another CFC method for processing. true or false, depending on whether or not the user has been authenticated.In all of these examples, a client-side event triggers a CFC call, passing and receiving data as needed. And for many ColdFusion-powered Flex applications, that may in fact be all you need.
But you may want more.
So far I have discussed Flex Builder, a client tool. There is also a Flex 2 server, called Flex Data Services (FDS for short). It gets installed and deployed on top of a J2EE server (possibly the same server running ColdFusion if you are using ColdFusion Enterprise and a J2EE deployment). Using FDS, you can compile MXML and ActionScript code on the fly (much like how you did in Flex 1.x). What makes FDS really compelling is the fact that it allows for a real bidirectional connection between the server and the client-side Flash application.
What does this mean? Consider the following scenarios:
<mx:DataGrid> displays results from a database search, but that data could be stale and you would never know it. What you want is for data changes to be immediately reflected on the screen of any clients that happen to be looking at that data (and not those who are not, obviously).If any of these scenarios resonate, then you've just defined a need for Flex Data Services. As I already explained, Flex Data Services allows for open connections between client and server. There are two primary benefits to this:
Server-to-client push: The ability to push data to the SWF file running in Flash Player without needing to use timers and polling. For example, you could do one of the following:
Notify a <mx:DataGrid> to update a specific row with changed data
. . . you get the idea.
While most of the FDS demos and examples seem to concentrate on the push aspect of FDS, it is data synchronization that is likely of greater interest to most of us ColdFusion developers—considering that most of the applications built in ColdFusion tend to be highly data-centric database front ends.
While FDS is primarily targeted at Java/J2EE development, the ColdFusion team has done a considerable amount of work to expose powerful FDS functionality to ColdFusion developers:
You can get started building ColdFusion-powered Flex 2 applications using just ColdFusion MX 7.0.2 and a Flex compiler (Flex Builder 2 or the free Flex 2 SDK). For applications that require data synchronization or server-to-client push, the best approach is to add Flex Data Services to the mix. And with Flex Data Services Express, available at no cost, there is no reason not to try FDS.