Home > Development > blogs
In this article I'm going to discuss ColdFusion and what it has built in to enable RIA development. I'm going to focus (mainly) on what ships with the server out of the box. I'm also curious as to what PHP and .Net ships with to help RIA developers. I'm (obviously) a CF guy and will admit I know little about PHP and .Net, so if you are a developer with RIA experience in that area, drop me a line at my blog as I'd like to follow this article up with details about those platforms.
There are multiple areas where ColdFusion helps the RIA developer. In this first article, I'm going to focus on serving up data to RIA clients. First let me be clear. When I say RIA development, I'm talking both about Flash/Flex and HTML-based AJAX applications. The techniques covered here will cover all of them.
So how exactly can we serve data to a RIA based application? Off the top of my head I can think of a few ways: XML, JSON, Flash Remoting, and Web Services.
ColdFusion has nice XML capabilities. It can easily create and work with XML. What isn't built in is a simple way to convert ColdFusion's native data types like queries or a arrays into XML. ColdFusion has shipped with WDDX support for years. WDDX was an early way to easily syndicate data and while this is technically XML, it isn't XML that is easily used in RIA applications. So in general, you need to create the XML yourself. Here is a real simple, manual example:
<cfset data = arrayNew(1)>
<cfset data[1] = "Foo">
<cfset data[2] = "Goo">
<cfset myxml = "<data>">
<cfloop item="a" array="#data#">
<cfset myxml &= "<item>#a#</item>">
</cfloop>
<cfset myxml &= "</data>">
While not terribly difficult, it does involve some work on your part. I promised I wouldn't mention external libraries, but I will quickly point out toXML, a component I created to convert ColdFusion data types into XML.
JSON is quite a bit simpler though. ColdFusion 8 supports a native serializeJSON function that makes converting data into JSON incredibly easy. (And of course it has deserializeJSON and isJSON functions as well.) Taking the XML example above, I could have converted the array into JSON like so:
<cfset myjson = serializeJSON(data)>
What makes the JSON support even more interesting is how it integrates with CFCS, which lets me touch on web services and flash remoting as well.
CFCs are ColdFusion Components. They are lightweight, object oriented-like (not pure OO!) files that allow for more sophisticated development. What makes them really handy to RIA developers is that they also allow for both flash remoting and web services. Consider this simple CFC:
<cfcomponent>
<cffunction name="getTime" access="remote" returnType="string">
<cfreturn now()>
</cffunction>
</cfcomponent>
Once placed under web root, this code can return the current time both to Flex and Flash via a Flash Remoting call, and also as a web service by simply appending ?wsdl to the URL. So if the CFC was named timeservice.cfc and located on my blog, the web service URL would be http://www.coldfusionjedi.com/timeservice.cfc?wsdl. That's it. No other special code is required.
So getting back to JSON - I said that support for JSON was integrated into CFCs, now let me describe how. In general when you request a CFC remotely, you get WDDX back. This is XML, but generally not what you would prefer. However, if you want to return basic XML, ColdFusion won't muck with that. It will leave it as is. When being called via Flash Remoting or Web Services, ColdFusion handles all the necessary conversion there as well. But you can also tell ColdFusion to convert results to JSON. All you have to do is add a returnFormat=JSON to your call (for example, http://www.coldfusionjedi.com/timeservice.cfc?method=gettime&returnformat=json) and the server will convert the result to JSON. Very slick, and very handy.
In the next blog entry, I'll discuss other Ajax features in ColdFusion, and also point out resources where to learn more.

Sorry for drifting off topic,
I'm curious to know, what does the community of this blog think about Flex with Ruby on Rails as back end?
In my opinion, a model view controller gives ease to managing an RIA with the beauty of front end Flex.