Welcome first of all,

I don't know if you are aware that you can return directly a query from the 
CFC. In flex side it will be available as event.result._items and you are able 
to bind it directly as an Array.

In your sample you could say in cfc:

<cfreturn getAllPersonnel>

in your mxml file you could have some 
public var dp:Array;
private function doResult(result:Array):Void {
        dp = result;
    }

in the Datagrid set the property dataProvider="{dp}"
and just replace your remote object result to 
result="doResult(event.result._items)"

I think, if I'm not mistaken, your datagridcolumns should have columnName in 
upper case when dealing with CFC structures.

Regards,

João Fernandes

-----Original Message-----
From: flexcoders@yahoogroups.com on behalf of rgwilson26
Sent: Fri 17-Feb-06 6:11 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] calling a cfc from flex
 
I am new to flex and working on calling a cfc that has a simple query 
in it. I want my query to populate a datgrid with all pertinant 
information. I am having a hard time converting from an array to a 
string to populate the DG. Any help in what I am missing would be 
great, or if there is an easier way to call a query and return data 
would be great!

************************
  getPersonnel.cfc
************************
<cfcomponent displayname="getPersonnel">
<cffunction name="getPersonnel" access="remote" returntype="string">
                
<cfset var arrayResult = ArrayNew(1)/>
                
<cfquery name="getAllPersonnel" datasource="spotDB">
SELECT * 
FROM dbo.ItemsInvolvedLOV
</cfquery>
                
<cfoutput query="getAllPersonnel">
<cfset structPersonnel = StructNew()/>
<cfset structPersonnel["ItemId"] = #getAllPersonnel.ItemId#>
<cfset structPersonnel["ItemType"] = #getAllPersonnel.ItemType#>
<cfset structPersonnel["ItemName"] = #getAllPersonnel.ItemName#>
<cfset arrayAppend(arrayResult,structPersonnel)/> 
</cfoutput>
<!--- Return Array to Flex--->
<cfreturn getAllPersonnel>
</cffunction>
</cfcomponent>


************************
  personnelNeeded.MXML
************************
ActionScript:
------------
private function doResult(result:Array):Void {
        
    var personnelObject:Object = new Object();  object 
    var personnelResult:Array = new Array();    

    for(var i=0; i < result.length; i++){
     personnelObject = result[i];
     personnelResult.push(personnelObject);
    }
    dgPersonnelNeeded.dataProvider = personnelResult;
    }

************************
  Remote Object
************************

<mx:RemoteObject id="ro" 
           endpoint="http://10.95.20.39:8500/flashservices/gateway";  
             source="cfdocs.components.getPersonnel"
              fault="mx.controls.Alert.show
(event.fault.faultstring, 'Error')" 
        showBusyCursor="true">
<mx:method name="getPersonnel" result="doResult(event.result)"/>
                
</mx:RemoteObject>


************************
  Datagrid
************************

<mx:DataGrid id="dgPersonnelNeeded" headerColor="#00CC33" 
height="300" textAlign="left" width="100%" wordWrap="true" 
editable="true">
<mx:columns>
<mx:Array>
<mx:DataGridColumn headerText="Name" columnName="name" width="225" />
<mx:DataGridColumn headerText="Title" columnName="title" width="650"/>
<mx:DataGridColumn headerText="Date" columnName="date" width="100" />
</mx:Array>
</mx:columns>
</mx:DataGrid> 


************************
  Click event button
************************
<mx:Button label="Get Records"  textAlign="center" width="100" 
click="{ro.getPersonnel()}"/>







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links



 






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

<<winmail.dat>>

Reply via email to