1 Reply Latest reply on Dec 6, 2007 6:35 PM by ntsiii

    Retrieving data from table and displaying in datagrid

    spacehog Level 1
      I have been reading the article, "Integrating Flex 2 with Coldfusion MX" and I am having a problem with the datagrid retrieveing data from the Access table. I am able to submit data via the form, but it does not display in the datagrid.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" creationComplete="userRequest.send()">
      <mx:HTTPService id="userRequest" url=" http://localhost:8501/flex2/returncfxml.cfm" useProxy="false" method="POST">
      <mx:request xmlns="">
      <username>{username.text}</username><emailaddress>{emailaddress.text}</emailaddress>
      </mx:request>
      </mx:HTTPService>
      <mx:Form x="22" y="10" width="493">
      <mx:HBox>
      <mx:Label text="Username"/>
      <mx:TextInput id="username"/>
      </mx:HBox>
      <mx:HBox>
      <mx:Label text="Email Address"/>
      <mx:TextInput id="emailaddress"/>
      </mx:HBox>
      <mx:Button label="Submit" click="userRequest.send()"/>
      </mx:Form>
      <mx:DataGrid id="dgUserRequest" x="22" y="128" dataProvider="{userRequest.lastResult.users.user}">
      <mx:columns>
      <mx:DataGridColumn headerText="User ID" dataField="userid"/>
      <mx:DataGridColumn headerText="User Name" dataField="username"/>
      </mx:columns>
      </mx:DataGrid>
      <mx:TextInput x="22" y="292" id="selectedemailaddress" text="{dgUserRequest.selectedItem.emailaddress}"/>
      </mx:Application>

      The CFC seems to be working fine because the INSERT statement functions. Any help would be greatly appreciated
        • 1. Re: Retrieving data from table and displaying in datagrid
          ntsiii Level 3
          All that declaritive code is difficult to debug. Try this below.
          Tracy

          Sample code using HTTPService, e4x, handler function to populate a list item.
          Also shows usage of AsyncToken.

          The DataGrid tag:
          <mx:DataGrid id="dg" dataProvider="{_xlcMyListData}" .../>


          The HTTPService tag:
          <mx:HTTPService id="service" resultFormat="e4x" result="onResult(event)" fault="..../>

          Script block declaration:
          import mx.rpc.Events.ResultEvent;
          [Bindable]private var _xlcMyListData:XMLListCollection;

          Invoke send:
          var oRequest:Object = new Object();
          oRequest.Arg1 = "value1";
          var callToken:AsyncToken = service.send(oRequest);
          token.callId = "myQuery1";

          Result Handler function:
          private function onResult(oEvent:ResultEvent):void {
          var xmlResult:XML = XML(event.result); //converts result Object to XML. can also use "as" operator
          var xlMyListData:XMLList = xmlResult.myListData; //depends on xml format, is row data
          _xlcMyListData = new XMLListCollection(xlMyListData); //wrap the XMLList in a collection
          trace(_xlcMyListData.toXMLString()); //so you can see exactly how to specify dataField or build labelFunction
          var callToken:AsyncToken = oEvent.token;
          var sCallId = callToken.callId; //"myQuery1"
          switch(sCallId) { //Process the result conditionally
          case "myQuery1":
          doQuery2(); //do whatever. this example calls another data service query
          break;
          ...
          }
          }//onResult