I thought Builder extensions operated in a funny web browser that meant you could use html, including forms, but returned data in some funny XML format. Oh how wrong I was. You can use html but only for outputting information. The most common way to write extensions is by using the built in Eclipse input types which pass data to ColdFusion via that funny XML format I spoke about earlier. They are great if you are looking to tie into Eclipse but I wanted some UI tools to list data, a textarea to edit and a nice chart.
[UPDATE 6/30/10: There is an easier way. Read this blog entry]
So, it was on to using Flex to build a front end that had the UI controls I needed and started by reading this great blog post by Terry Ryan.
This method works by writing a CFC webservice exposed via WSDL to pass data back and forth. Terry used XML as a data transformation protocol. Now, for me, XML is like warm beer. Its there to be drunk, but first, lets see if there's a cold one around. I decided to go with using cf queries to pass data around. Combined with the Data Services panel in Flex Builder 4 this made the data transmission easy.
One drawback to this approach is that Data Services assumes the URL for the webservice will not change. To get around this I we need to pass that path to Flex via URL variables when we call the swf from within our extension. Don't worry its actually simpler than that sounds.
Starting on the Flex side, I opened up the generated services file and removed any mention of the wsdl path. This gets replaced with what is passed in during the declaration of the service, which I bind to a variable that is set based on a function called during preinitialize. Here's the code:
Thats a slightly simplified version. All the code is available in the subversion repository. (If you are a Flex developer and you know a better way please let me know. I'm a newbie when it comes to Flex.)
On the ColdFusion side we need to pass in the server path to the swf. Here's code for that, loosely based on Terry's code.
Overall I found building an extension with Flex pretty straightforward and just by using the default Spark look the UI is pretty attractive.