Captivate Tutorial: Viewing a ColdFusion Query in a Flex DataGrid
I have long awaited for this day to post my first Captivate tutorial. The first topic that I am presenting on is one that I struggled with when I was first learning Flex 2 and also one that I know many other developers have an issue grasping. It is the subject of bringing in a basic ColdFusion query to a Flex application and showing it in a DataGrid. It is really not all that hard, but unless you know how to do it, there is really no way in "figuring it out".
I decided a Captivate tutorial would demonstrate this best, so without further delay, here is the tutorial URL: http://www.kylehayes.info/captivate/QueryToDatagrid/QueryToDataGrid.htm



@Stefan: Thank you, and I will add your suggestions to the list!
I agree that people would really appreciate seeing how you can get a successful add/update/delete with the given example. This is for sure where I want to be heading!
Is there a reason that you have chosen remoting instead of Data Services? It seems like Data Services would be amazing if one could ever get them to work b/c of the possibility of having the real time data updates as changes are made.
As we speak I'm downloading the Coldfusion update 7.02 in hopes that it will fix the isssue!
Have you considered doing some sort of explanation about the .config files that you need for remoting and data services? I think people might appreciate that.
As for the Data Services comment, the reason why I use remoting is because I can afford it ;-). You see Flex Data Services is a very expensive product (somewhere around $20k I believe). Granted there is a lite version. But remoting is very useful when you don't require live data updating. You can still do a time based server pull without remoting. Remoting is really great if you need to have server push, like a chat messaging client.
I think it is safe to assume that I will be doing a tutorial sometime in the future on how to work with Flex Data Services ;-)
I'm really excited this! Are you sure it costs 20k? I have something that is called Data Services running on my computer. I thought I paid a few extra hundred bucks for it but thought I would want the capability. Do you think that's why it never worked? It was never installed to begin with?
In any case, kyle saved me by pointing out that I had written Coldfusion instead of ColdFusion and thus caused the whole thing not to work. I think I was also running the 7.0 instead of 7.02.
A time based server pull = just periodically re-downloading the dataset and refilling the grid? Makes sense, do you just do that with an actionscript timer?
Above you mentioned that we are recreating what the wizards do. Which of the wizards corresponds to what we are doing?
Active Record CFC
Bean CFC & DAO CFC
Flex Data Service Assembler CFC
Yes, Scott, when I referred to the a time based server pull (or poll) it would basically be an ActionScript Timer event that calls the <strong>get</strong> function of the RemoteObject that is updating your dataset.
In response to the wizard question, we have not done what the wizards are doing yet, but it is in the works. The wizard that I am talking about is after you install the Flex Builder ColdFusion extensions (which the Flex Builder prompts you to do after you install Flex Builder) there is a wizard when you go to create a <strong>New Project</strong>. It allows you to create a CRUD style application based on a datasource. I actually often times have issues with it, but nonetheless, I would like to do a tutorial that shows how to do basic actions like that that interact with CF components.
If you look at the documentation that I found on Adobe's site for Coldfusion, "Using Coldfusion with flex" http://download.macromedia.com/pub/documentation/e..."
i think that is mostly focuses on data services?
If you were to add a row to your recordset, would you send an http post to server to take care of the include and then simply add a "row/set/set of variables" to the array collection? I guess that would work b/c it would reflect the change. I suppose you could also simply redownload the whole dataset, but I imagine that could be problematic if you were dealing with a huge dataset.
Thanks for explaining the periodic calls.
Do you recommend the wizard?
As far as how you would do the insert, what you would do, is build a function in your CFC called say addArtist or something like that and define the appropriate arguments such as firstName, lastName, email etc. Then you simply call the remoteObject just like you did to get records accept this time you are actually going to pass it some vars.
So if you had a form in your Flex app that had the variables that you wanted to pass to the CFC, then maybe you would do the following:
artistRO.create(txtFirstName, txtLastName, txtEmail);
and that would fire off the create method inside your artistRO object. It is pretty simple. But don't worry, I will show you how to do this in time with a Captivate example :-)
The services configuration includes a channel-definition 'my-cfamf' that has an endpoint with a context.root token but a context root has not been defined. Please specify a context-root compiler argument.
I'm not 100% sure what it means. Why would the file be ok for one project and not be alright for another? Was adding the reference in the compiler the wrong way to add this functionality?
<mx:datagrid>
<mx:columns>
<mx:DataGridColumn headerText="First Name" dataField="firstName" />
<mx:DataGridColumn headerText="Last Name" dataField="lastName" />
<mx:DataGridColumn headerText="Email" dataField="email" />
</mx:columns>
</mx:datagrid>
The headerText can be whatever you want it to be. The datafield, is the column that you want to display.
I'm not running IIS, as in your example.
Randy
I appreciate your help. I'll look to this site for more CF/Flex tutorials.
Randy
Hope this lengthy explanation helps :-)
Did you ever address why you think data services would cost 20,000 dollars??
http://www.adobe.com/products/flex/productinfo/buy...
NOTE: Enterprise edition is $20,000 and Department edition (100 Users) is $6,000
I'm sorry to stick you with that. I thought it was you that told that to me. I guess someone must have told it to me because the 20,000 dollar number does match up to something. I just bought the Adobe Flex 2 training from the source and am trying to check out how that works.
One thing that remains unclear to me, is that if I always test my programs with the applications running on localhost, will it be a huge pain when I want to deploy the application to a different server? Have you ran into that yet?
P.S.
I've only had it for a few hours but I don't think they supply a tutorial like the one that you supply with the simple task of returning a query. I think they pretty much follow the path of starting you off with http requests and calling XML files from servers. This works fine until you have to start pushing the data back... The only way I could think of tackling that issue was to post to "web services" or coldfusion files that can do inserts and updates based on information that you would push via http via a query string. Oh... the possibilities.
You describe in a couple of minutes what it took me several of days to get working.
Really looking forward to the CRUD tutorial.
//Morgan
Jeff
After installing the plugin was there some other configuration that I needed to do? BTW I'm working on a MAC so I'm not sure if that changes things.
Anyway, as for your error, it does have to do with your services-config file. Would you mind posting the text of that file at http://kylehayes.privatepaste.com/xml/ and then posting the link here? If you don't want anyone else to view it later, make sure you set an expiration. Thanks.
Here is the link you asked for: http://kylehayes.privatepaste.com/ca19to4QGx
Thanks again.
I just upgraded Flash Player to see if that is the problem and the error doesn't pop up now, but I only get a blank flex screen. No datagrid or anything. But I AM getting closer.
it was working before now it's not, can help me to get it back to working?
Watching on video, which takes forever to load is not very "usable".
However, your demo "title" interests me so i shall continue waiting...
I have the latest version of ColdFusion 7 and Flex 2.0. Any ideas what I am doing wrong? HELP?
Thanks
there is a hot fix from adobe for the bug 'unexpected url found'..
get the fix - hotfix 2 from adobe site
http://kb.adobe.com/selfservice/viewContent.do?ext...