2 Replies Latest reply on Nov 14, 2006 12:16 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 always advise using a result handler function instead of binding directly to the result because binding is so hard to debug.

          I also advise using resultFormat="e4x" because the XML object is easier to work with than the default Object. For example, in a handler function you can use toXMLString() to see exactly what your data looks like. This is much harder if you are using mx:Object. Now, I don't know CF, so I can't tell what kind of object the query is returning, so the xml format might not work for you.

          Finally, the column display depends on the structure of your data. For dataField specifications to work, the specified field must be a top-level property of the item object. If it is nested in another object, yo will have to use a labelFunction.

          Whatever, you MUST know exactly what your data structure is in order to consume it successfully. Hence the result handler function, where you can alert or trace as needed.

          Tracy
          • 2. Re: Datagrid empty with webservice call
            ntsiii Level 3
            Also, this is not a Flex Builder 2 question, so it should go in the General Discussion forum instead of here.