1 Reply Latest reply on Sep 14, 2006 2:40 PM by Bill Sahlas

    WebService and XMLListCollection

    eclipse57
      I'm new to Flex and I'm having some trouble with getting a DataGrid to populate from an XMLListCollection and WebService. I know that the data is being received, because it shows up in a text area. Also, when I change the XMLListCollection to an ArrayCollection it works fine.

      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" verticalGap="10">
      <mx:Script>
      <![CDATA[
      import mx.controls.Alert;
      ]]>
      </mx:Script>

      <mx:WebService id="wsBlogAggr"
      wsdl=" http://weblogs.macromedia.com/mxna/webservices/mxna2.cfc?wsdl"
      useProxy="false"
      showBusyCursor="true"
      result="Alert.show('Received', 'Received');"
      fault="Alert.show(event.fault.faultString, 'Error');">
      <mx:operation name="getMostPopularPosts" resultFormat="e4x">
      <mx:request>
      <daysBack>30</daysBack>
      <limit>5</limit>
      </mx:request>
      </mx:operation>
      </mx:WebService>

      <mx:XMLListCollection id="xc" source="{wsBlogAggr.getMostPopularPosts.lastResult}"/>

      <mx:DataGrid dataProvider="{xc}" width="50%" horizontalCenter="12">
      <mx:columns>
      <mx:DataGridColumn dataField="postTitle" headerText="Top Posts"/>
      <mx:DataGridColumn headerText="Clicks" dataField="clicks" width="75" />
      </mx:columns>
      </mx:DataGrid>

      <mx:TextArea y="245" width="307" height="160"
      id="ta"
      text="{wsBlogAggr.getMostPopularPosts.lastResult}" horizontalCenter="0"/>

      <mx:Button label="Retrieve XML" click="{wsBlogAggr.getMostPopularPosts.send()}" y="476" horizontalCenter="0"/>

      </mx:Application>

      Sorry for the basic question, and thanks in advance.

      Dan
        • 1. Re: WebService and XMLListCollection
          Bill Sahlas
          You can go right from the WS result to the DataGrid when the resultFormat is set to "object". Otherwise you should review this document/sample for syntax and "caveats" - http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=L iveDocs_Parts&file=00001142.html

          Have you given the "object" resultFormat a test?

          <?xml version="1.0"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" verticalGap="10" creationComplete="initializeApp();">
          <mx:Script>
          <![CDATA[
          import mx.controls.Alert;
          private function initializeApp():void
          {
          wsBlogAggr.getMostPopularPosts.send();
          }
          ]]>
          </mx:Script>

          <mx:WebService id="wsBlogAggr"
          wsdl=" http://weblogs.macromedia.com/mxna/webservices/mxna2.cfc?wsdl"
          useProxy="false"
          showBusyCursor="true"
          fault="Alert.show(event.fault.faultString, 'Error');">
          <mx:operation name="getMostPopularPosts" resultFormat="object">
          <mx:request>
          <daysBack>30</daysBack>
          <limit>5</limit>
          </mx:request>
          </mx:operation>
          </mx:WebService>

          <mx:DataGrid dataProvider="{wsBlogAggr.getMostPopularPosts.lastResult}"
          width="50%" horizontalCenter="12">
          <mx:columns>
          <mx:DataGridColumn dataField="postTitle" headerText="Top Posts"/>
          <mx:DataGridColumn headerText="Clicks" dataField="clicks" width="75" />
          </mx:columns>
          </mx:DataGrid>

          <mx:TextArea y="245" width="50%" height="50%"
          id="ta"
          text="{wsBlogAggr.getMostPopularPosts.lastResult}" horizontalCenter="0"/>

          </mx:Application>