4 Replies Latest reply on Apr 17, 2007 7:00 AM by michaeljbaird

    WebService, HttpService, namespace

    dave cragg Level 2
      I've happily been using htttpService calls, connecting to my own PHP scripts without many problems. But I now have to use services provided by a third party. The services can be used with either webService or httpService, but all return xml data with an included namespace. (xmlns=" http://www.example.com/api"). This seems to make life difficult, and I suspect I'm missing some magic ingredient. My biggest problem is populating a datagrid with the returned data.

      1. Problems using ArrayCollection
      If I use the webService call, and *don't* use the e4x resultFormat, I can populate the grid by setting the dataProvider to service.operation.lastResult. This works OK.

      If, instead, I set the dataProvider to an mx:ArrayCollection object like below, it doesn't work. No data appears in the grid. (This method is illustrated in a number of examples in the docs.)

      <mx:ArrayCollection id="statesAC" source="service.operation.lastResult" />

      But if I add an mx:Binding element, and point this to the ArrayCollection, it works.

      <mx:Binding source="service.operation.lastResult" destination="statesAC" />
      <mx:ArrayCollection id="statesAC" />

      I should be happy that this works, but I'd be more comfortable knowing why the middle approach doesn't, especially as the docs seem to push this as a preferred approach. Any thoughts?

      2. Problems using XMLListCollection

      This is more troubling, as I'd prefer to use an XMLListCollection to populate the grid.

      I've had no success using the webService approach. I can't get any of the above techniques for ArrayCollection to work for an XMLListCollection. No data appears in the grid.

      I've had more success with httpService and handling and converting the XML directly in the service's result event. But this also is not straightforward:

      -- I have to set a namespace, using either "default xml namespace = ...." or "use namespace ...". Without doing this, I'm unable to extract an XMLList from the returned XML. (The XMLList is used to make the XMLListCollection for the DataGrid.)

      -- It seems that the DataGrid's dataField properties are not recognised when a namespace is being used, even when the above-mentioned namespace settings are in place. A labelFunction has to be used, but even that is not straightforward.

      Assuming a property name of "Name", this won't work for a column setting (no data appear in the column):
      <mx:DataGridColumn dataField="Name" headerText="Name"/>

      This will work:

      public function gridFunction(item:Object, column:DataGridColumn):String {
      return item.Name;
      }
      <mx:DataGridColumn headerText="Name" labelFunction="gridFunction"/>

      But this won't (although it works with XML that has no namespace set):

      public function gridFunction(item:Object, column:DataGridColumn):String {
      var fieldName:String = column.dataField;
      return item[fieldName];
      }
      <mx:DataGridColumn headerText="Name" labelFunction="gridFunction"/>

      The labelFunction approach, although it displays data, still leaves isues with sorting. I'm sure this is not how things are meant to be.

      Any insights as to how to make this easier would be appreciated, especially with regard to working with XMLListCollections.