1 Reply Latest reply on Nov 16, 2006 4:02 PM by ntsiii

    Datagrid empty with WebService call

    warf0x0r
      I have a cfc that I'm using as a webservice:

      <cfcomponent output="false">
      <cffunction name="contactlist" access="remote" returntype="query">
      <cfargument name="SiteID" required="yes">
      <cfset var cList="">
      <cfquery name="cList" datasource="kbase">
      SELECT Contacts.Name, Contacts.Title
      FROM Contacts INNER JOIN
      Sites ON Contacts.SID = Sites.SID
      WHERE Sites.Site_ID = '#ARGUMENTS.SiteID#'
      </cfquery>
      <cfreturn cList>
      </cffunction>
      </cfcomponent>

      This cfc works just fine if I call it with coldfusion in a .cfm page...

      I'm using the following code in flex:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientColors="[#57cb1f, #c1f2aa]" creationComplete="testWS.contactlist.send()" viewSourceURL="srcview/index.html">
      <mx:WebService id="testWS"
      wsdl=" http://localhost/cftest/contactlist.cfc?wsdl"
      useProxy="false">

      <mx:operation name="contactlist">
      <mx:request>
      <SiteID>{dropBox.value}</SiteID>
      </mx:request>
      </mx:operation>

      </mx:WebService>

      <mx:DataGrid x="288" y="201" dataProvider="{testWS.contactlist.lastResult}" id="grid" width="257" fontFamily="Times New Roman" fontSize="10" color="#000000">
      <mx:columns>
      <mx:DataGridColumn headerText="Prefix" dataField="Title"/>
      <mx:DataGridColumn headerText="Name" dataField="Name"/>
      </mx:columns>
      </mx:DataGrid>
      <mx:ComboBox x="288" y="143" id="dropBox" change="testWS.contactlist.send()" enabled="true">
      <mx:Object label="UMD001" value="UMD001" />
      <mx:Object label="MAI001" value="MAI001"/>
      </mx:ComboBox>

      </mx:Application>

      and when I view the page my datagrid is empty, but it does change the number of rows in the grid when I change the value in the drop downs. I'm just starting flex so there may be errors in the dataProvider section of the data grid declaration. If anyone has any ideas/suggestions it would be much appreciated
        • 1. Re: Datagrid empty with WebService call
          ntsiii Level 3
          I don't know CF, but the problem is that the structure of your data is not exactly what you expect.

          Binding directly to the lastResult is very hard to debug. Instead, specify a resultHandler function on the operation.
          result="onResult(event)" //note the event argument, it is critical
          In that result handler you can examine the event.result to determine exactly what your data looks like in Flex.
          private function onResult(oEvent:ResultEvent) {
          var oResult:Object = oEvent.result;
          trace(oResult.Title); //does this trace out the value you expect?

          For the dataField spec to work, the specified property must be a top-level property of the dataProvider Item. if the value is in a nested object, you will need to use a labelFunction.

          If you can get CF to send you XML, things are much easier.

          Tracy