2 Replies Latest reply on Jun 5, 2006 7:00 AM by PhilRV6

    Web Service -> ComboBox

    PhilRV6
      I'm just learning Flex. Decided to learn v2. I'm trying to populate a ComboBox from the data returned from a web service. I've spent hours looking through the docs and examples, but have not been able to find any help or examples. Has anyone done this, and could you provide me a couple of examples and possibly some help? Below are snippits of my code.

      The web service is a CF web service that returns a query with one field (name) in each record. I've tested it witn CFML so I know that it works. Also, I've been able to populate a DataGrid with it.

      <mx:WebService id="wsDSNinfo"
      wsdl=" http://localhost:8500/test/DSNinfo/DSNinfo.cfc?wsdl"
      useProxy="false"
      showBusyCursor="true">
      <mx:operation name="getDSNinfo"></mx:operation>
      <mx:operation name="VerifyDSN"></mx:operation>
      <mx:operation name="getTables">
      <mx:request>
      <theDSN>xpressline</theDSN>
      </mx:request>
      </mx:operation>
      <mx:operation name="getTableDetails"></mx:operation>
      <mx:operation name="getTableRecords"></mx:operation>
      </mx:WebService>

      <mx:ComboBox x="10" y="10" id="cbxTables" dataProvider="{wsDSNinfo.getTables.lastResult}">
      <mx:Object label="Name" data="name" />
      </mx:ComboBox>

      Here's the error I get in Developer.
      "Multiple initializers for property 'dataProvider'. (note: 'dataProvider' is the default property of 'mx.controls.ComboBox')."
      I have an idea of what's going on, but havn't been able to discover how to fix it.

      Thanks for any help you can give.

      Sincerely: Phil Spingola
        • 1. Re: Web Service -&gt; ComboBox
          Level 7
          Many MXML tags have a "default property," which means, whenever you write

          <mx:SomeTag>
          anything here
          </mx:SomeTag>

          that that is equivalent to writing

          <mx:SomeTag>
          <DEFAULT_PROPERTY>
          anything here
          </DEFAULT_PROPERTY>
          </mx:SomeTag>

          which is also equivalent to writing

          <mx:SomeTag DEFAULT_PROPERTY="anything here" />

          This may seem odd at first, but the idea is to provide a convenient shorthand
          for common operations. In the case of a ComboBox, for example, since the
          default property is dataProvider, the following are equivalent:

          <!-- case one: data separate from the combo box -->
          <mx:Array id="mydata">
          ...
          </mx:Array>
          <mx:ComboBox dataProvider="myData" />

          <!-- case two: data inside the combo box, explicitly specified
          as being the data provider -->
          <mx:ComboBox>
          <mx:dataProvider> <!-- lower case 'd' -->
          <mx:Array>
          ...
          </mx:Array>
          <mx:dataProvider>
          </mx:ComboBox>

          <!-- case two: data inside the combo box; since dataProvider
          is the default property of ComboBox, you don't have to
          explicitly specify mx:dataProvider tag -->
          <mx:ComboBox>
          <mx:Array>
          ...
          <mx:Array>
          </mx:ComboBox>

          That's why the compiler complains when you write a ComboBox with both a
          dataProvider attribute and child tag which are not explicitly specified as
          being some other property.

          So, how do you fix it? Like this:

          <mx:ComboBox dataProvider="{wsDSNinfo.getTables.lastResult}"
          labelField="name" />

          Later, from code, to get the rest of the data in the currently selected item,
          use myComboBox.selectedItem.


          --
          Mike Morearty
          Developer, Flex Builder team
          http://www.morearty.com/blog


          PhilRV6 wrote:
          > I'm just learning Flex. Decided to learn v2. I'm trying to populate a ComboBox
          > from the data returned from a web service. I've spent hours looking through the
          > docs and examples, but have not been able to find any help or examples. Has
          > anyone done this, and could you provide me a couple of examples and possibly
          > some help? Below are snippits of my code.
          >
          > The web service is a CF web service that returns a query with one field (name)
          > in each record. I've tested it witn CFML so I know that it works. Also, I've
          > been able to populate a DataGrid with it.
          >
          > <mx:WebService id="wsDSNinfo"
          > wsdl="<a target=_blank
          > class=ftalternatingbarlinklarge
          > href=" http://localhost:8500/test/DSNinfo/DSNinfo.cfc?wsdl"
          > "> http://localhost:8500/test/DSNinfo/DSNinfo.cfc?wsdl"
          > </a> useProxy="false"
          > showBusyCursor="true">
          > <mx:operation name="getDSNinfo"></mx:operation>
          > <mx:operation name="VerifyDSN"></mx:operation>
          > <mx:operation name="getTables">
          > <mx:request>
          > <theDSN>xpressline</theDSN>
          > </mx:request>
          > </mx:operation>
          > <mx:operation name="getTableDetails"></mx:operation>
          > <mx:operation name="getTableRecords"></mx:operation>
          > </mx:WebService>
          >
          > <mx:ComboBox x="10" y="10" id="cbxTables"
          > dataProvider="{wsDSNinfo.getTables.lastResult}">
          > <mx:Object label="Name" data="name" />
          > </mx:ComboBox>
          >
          > Here's the error I get in Developer.
          > "Multiple initializers for property 'dataProvider'. (note:
          > 'dataProvider' is the default property of 'mx.controls.ComboBox')."
          > I have an idea of what's going on, but havn't been able to discover how to fix
          > it.
          >
          > Thanks for any help you can give.
          >
          > Sincerely: Phil Spingola
          >
          • 2. Re: Web Service -&gt; ComboBox
            PhilRV6 Level 1
            Thanks much Mike. That worked. The only think different that I had to do was to type the labelField value ,"NAME" in caps. I'm finding that the existing doc is not really helping me very much. Is this just me, or are there clearer docs on the way. Your explanation was very clear and helpful.

            Thanks: Phil