Link to home
Create AccountLog in
Avatar of david_sternberg

asked on

Having trouble displaying data from a webservice call in Adobe Flex 2

I am trying to populate a datagrid from a ColdFusion Component (get_functional_currencies.cfc).  It is not working. All that shows up is a blank data grid with the headers of func_currency_code and func_currency_desc. The flex code is listed in the code snippet as well as the  component.

I must being missing something simple here.

ColdFusion Component:
 <!--- Get all functional currencies --->  
 <cffunction name="get_func_currencies" access="remote" returnType="query">      
	 <cfquery datasource="#APPLICATION.DATASOURCE#" name="get_currencies">
		select func_currency_code,
		from tshr_func_currency_tbl
		order by func_currency_desc
 	<cfreturn get_func_currencies> 
Flex Code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="absolute" xmlns="*">
    	<mx:operation name="get_func_currencies"/>
	<mx:DataGrid dataProvider="{getCurrencies.get_func_currencies}">
			<mx:DataGridColumn dataField="func_currency_code"/>
			<mx:DataGridColumn dataField="func_currency_desc"/>

Open in new window

Avatar of Robinsonx6
Flag of Mauritius image

Have you tested the CFC without using flex.
Avatar of david_sternberg


Yes, it has been tested.
im looking into this currently as i have just run a test and am having the same issue of having a  blank datagrid ill get back to you once i have some answers.


First you should call the service somewhere. I don't see a service call. try this:

<mx:Application xmlns:mx="" layout="absolute" xmlns="*"

than the dataprovider should bind like this:

<mx:DataGrid dataProvider="{getCurrencies.get_func_currencies.lastResult}">
                  <mx:DataGridColumn dataField="func_currency_code"/>
                  <mx:DataGridColumn dataField="func_currency_desc"/>
juliano im not sure about for david_s but your solution isnt working for me and my lastResult is returning an array i can tell this by running an Alert in the ResultEvent
Well im a bit confused here and am wondering if there is a bug somewhere in flex because if you follow the following links examples which should work and is the same as julianos solution it doesnt work still produces a blank datagrid.

the returned result appears to be a nested array each with a length of 1

Still lokking into this will update when i get further
sorry forgot the link

here it is
Hi i have a working solution. use a remote object instead of a webservice for two reasons

1. remoteobjects  are faster than webservices at communication which will make your users happyer

2. webservices appear to be bugged and the remote object works

try the attached code and alter it to your cfc path

Please Note i have tested this code fully and it works binding to the Datagrid
if you need any further help please ask

<mx:RemoteObject id="myquery"
	<mx:method name="GetAllCustomerBooks" result="GetAllCustomerBooksResult(event)" />
<mx:DataGrid x="50" y="143" width="372" id="dgBooks" dataProvider="{LibraryQuery.GetAllCustomerBooks.lastResult}">
				<mx:DataGridColumn headerText="Column 1" dataField="Identity"/>
				<mx:DataGridColumn headerText="Column 2" dataField="CustomerName"/>
				<mx:DataGridColumn headerText="Column 3" dataField="DateCreated"/>
				<mx:DataGridColumn headerText="Column 3" dataField="Open"/>

Open in new window

Yes, I was looking at the <mx:remoteobject> as well but could not figure out how to set up the source attribute. This is why I went with the >mx:webservice>. In this case the source is "CashBook-debug.cfc.CashBook." I would be happy to use this solution if I could get help on setting up the source.

Dave S.
try what I posted before but keep a simple datagrid setup like this:

<mx:DataGrid dataProvider="{getCurrencies.get_func_currencies.lastResult}" />

please post what happens. For the example you posted first to work, we need to configure the datagrid a bit more. If you please could post what is shown in the simple datagrid I can have a better idea of what kind of data is coming from the cf, since i can't test the cf code here.  
ok the source is quite easy once you know how here is the solution

in my case the url of the cfc is

so as we know the is the root of the ColdFusion Server remove this this leaves us with


as ColdFusion uses the period instead of the slash replace the slashes with periods which gives us the source of


then remove the .cfc

which gives us


Hi again juliano,

Regarding this question i have been trying for many hours to get the webservice method working and have used the correct binding in both the datagrid and columns to no avail, i have also read in many forums that other people are suffering the same, i do think this is a bug in flex.

If you have a working sample on this then i would love to have a look because i think its important for us to know all the different working options

But for this question if he doesnt need to you a webservice then the remote object is better for him as they are faster than webservices.


Yes, I understand that. I have seen that in examples as I have mentioned before. But, it looks like you are running your RIA(flash application) on the same machine as you Coldfusion server. That is not "remote" enough for me. My users need to be able to call the remote object from their machine. How is the "source" set up in that case?

Thanks Dave S.
i use remoteobjects for our intranet, i believe this is specified in the endpoint please dont quote me on this perhaps juliano knows, however i will resaerch this quickly for you
ive done some digging and yes it appears to be the endpoint i vaguely remember doing this for an air app but unfortualy i cant find the project here on my home computer

ColdFusion has an flex2gateway and you set the endpoint to the url for the coldfusion server you are trying to reach


you must also place a crossdomain xml file into the route of the remotewebserver else the call gets rejected as a security violation but this bit is easy

i must go out now for a bit before the wife kills me but ill be back in about 1 hour
Here is a working sample for webservices. I've used webservices a lot. Also because of security issues , yes, you should place a crossdomain.xml in the server where webservices are being served.
<?xml version="1.0" encoding="utf-8"?>
			import polito.util.CollectionUtil;
			import dto.Contato;
			import mx.controls.Alert;
			import mx.collections.ArrayCollection;
			private var contatos:ArrayCollection;
			private function initApp():void{
			private function resultHandler(e:ResultEvent):void{
				if(e.result is ArrayCollection){
					contatos = e.result as ArrayCollection;
			private function faultHandler(e:FaultEvent):void{,e.fault.faultString);
         <mx:WebService id="agendaService"
	<mx:Panel label="AGENDA" width="470" height="406" layout="vertical" title="Agenda" 
		horizontalAlign="center" verticalAlign="middle" fontSize="10">
		<mx:DataGrid width="100%" height="100%" dataProvider="{contatos}">
				<mx:DataGridColumn headerText="Nome" dataField="nome"/>
				<mx:DataGridColumn headerText="Telefone" dataField="telefone"/>
				<mx:DataGridColumn headerText="Email" dataField="email"/>
		<mx:ControlBar width="376">
			<mx:TextInput id="searchText"  width="271"/>
			<mx:Spacer width="100%"/>
			<mx:Button id="searchButton" label="Buscar" click="agendaService.GetByNameOptimized(searchText.text)" />

Open in new window

im now confused because thats exactly the same as my webservices one which also didnt populate the datagrid
our code is doing exactly the same so i cant understand why my inst populating

Im finding this useful thanks juliano
perhaps its something wrong with my cfc

	<cffunction name="ReturnCustomerIdentity" access="remote" returntype="string" hint="This will return the identity when passed a customer name">
        <CFARGUMENT name="CustomerName" type="string" required="yes">
        <CFQUERY name="get_customer_Identity" datasource="localCashBook">
            Select Identity 
            FROM books 
            WHERE CustomerName = '#arguments.CustomerName#'
        <CFRETURN get_customer_Identity.Identity>
    <cffunction name="GetAllCustomerBooks" access="remote" returntype="query" hint="This will return all the customer books data as a query">
		<CFQUERY name="get_all_customerbook_data" datasource="localCashBook">
            SELECT Identity, CustomerName, DateCreated, Open 
            FROM books
        <CFRETURN get_all_customerbook_data>

Open in new window

First, my only problem is: I'm not used to coldfusion. If it were Java, C# or PHP I would do a better job looking at your code, but let's see what we can do. if you just print the result from CF to a html table, or xml how does it look like? Or how does the webservice response XML look like? Can you debug the flex application and put a breakpoint in the resultHandler of webservice, so we can see how it is parsing the data, and what data is actually brought from the webservice call? If you can do some print screens and post here would help a lot.

Also I just saw in the original post the following code:
<cfreturn get_func_currencies>

Shouldn't it be a variable being returned not the function (because get_func_currencies is the name of teh function, where is the query result being returned)?

Also when testing the webservice via the CFMX Admin page, is it working fine?  
no David_S is correct in his CFReturn tag

im about to test the endpoint using an air app which will correctly test the RemoteObject on a Remote Server, ill post back the results as soon as i complete the test and get an accurate return
Avatar of Robinsonx6
Flag of Mauritius image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
OK, so one of my books has a great example of a <mx:RemoteObject>. I tried just doing the hello world example and I am getting a totally different error although ithe code looks pretty simple to me. Display a label of hello world.

Here is a step by step of what is happening. I really think it has to be the way Flex is saving my configuration files.

1. I chose this time to create a new project. The book says to use the second object of Coldfusion Flash Remoting Service.
2. I choose the root folder of c:\CFusionMx8\wwwroot
3. The Root URL: is http:/localhost:8500/
4. Clicked Finshed.
5. I created the HelloWorld.cfc in the c:\inetpub\wwwroot\cfc directory (code snippet)
6. I created the code hello world mxml code  (LECharting.txtt)
7. I try to compile and I get an "unknown error" in the debug perspective(see .gif file).
8. Attached also is a copy of my services-config.txt file.

Can this really be that bad? I mean the one thing that attracted my to Coldfusion 8 years ago was how easy it was to query the database. This is really giving me a bad taste in my mouth.

Dave S.
	<cffunction name="helloWorld" access="remote">
		<cfreturn "Hello World">

Open in new window

There is nothing wrong with the mxml to throw this error

When you created your new project did you specify to use coldfusion as your server side this is in one of the first screens of the new flex app wizard.

remeber you where using the remote object fine in your other applcation above, and remeber to set your endpoint for it to be fully remote

p.s. this does appear to be a different question.