Expand my Community achievements bar.

Basic webService, xml and DataGrid

Avatar

Level 1

Hi Guys,

I try to use this code to connect my Flex App to webService (java) and display a simple Person list data to Datagrid.

The xml loading is Ok, this is the returned XML from webService:

<people>

  <person>

    <name>AAAA</name>

  </person>

  <person>

    <name>BBBB</name>

  </person>

</people>

When I click in the button the debug doesn't show errors, but the dataGrid doesn't display any data....

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
        <![CDATA[
            import mx.rpc.events.ResultEvent;
            import mx.rpc.events.FaultEvent;
            import mx.controls.Alert;

            public function faultHandler(ev:Event = null):void{
             Alert.show("Fault: "+FaultEvent(ev.target).message);
            }
           
            [Bindable] public var responseXML:XML;
           
            public function resultHandler(ev:Event = null):void{
                var responseString:String = String(XML(ResultEvent(ev).result).descendants("return")[0]);
                responseXML = XML(responseString);
            }
        ]]>
    </mx:Script>

    <mx:WebService
        id="srv"
        wsdl="http://localhost:8084/FLEXTEST/NewWebService?wsdl">
        <mx:operation
            name="findPersonEntities"
            resultFormat="e4x"
            fault="faultHandler(event)"
            result="resultHandler(event)"/>
    </mx:WebService>
   
    <mx:DataGrid id="dgGrid" dataProvider="{responseXML.people.person}">
     <mx:columns>
         <mx:DataGridColumn dataField="name" headerText="Name" />
     </mx:columns>
    </mx:DataGrid>
    <mx:Button label="Call Service Method" click="srv.findPersonEntities();" />

</mx:Application>

Could someone help me? Thanks!

1 Reply

Avatar

Level 1

Not sure if this helps, but try to cast your responseXML to another variable of XMLList type and provide that as the data source.  

Note: I am a beginner to Flex who is also working around similar problems.