5 Replies Latest reply on May 23, 2007 3:10 PM by bitwyse

    ArrayCollection as a Data Provider

    bitwyse Level 1
      I have a simple application that pulls data from a web service and populates a data grid. That works fine. However, I want to use an ArrayCollection to populate the data grid as I want to use the ArryCollection in other parts of the appliation.

      If I use the webservice last result as the data provider for the data grid it works fine. If I use the ArrayCollection as the data provider for the data grid it does not work.

      Can anyone point me in the right direction ???

      <mx:ArrayCollection id="arrayOfProjects" source="{ArrayUtil.toArray(wsProjectInformation.getControlsProjects.lastResult)}"/>
      <mx:DataGrid id="dgProjects" dataProvider="{arrayOfProjects}"
      .........<mx:columns>
      ............<mx:DataGridColumn dataField="projectID" headerText="Project ID" width="100"/>
      ............<mx:DataGridColumn headerText="Project Name" dataField="projectName"/>
      ............<mx:DataGridColumn headerText="Doc UNID" dataField="docUNID" visible="false"/>
      ........</mx:columns>
      </mx:DataGrid>
        • 1. Re: ArrayCollection as a Data Provider
          batmitra Level 1
          Hi
          when you try to bind a dataprovider whith an array collection, you must first make an instance of that array, on the result function form the webservice, and you must fill the arraycollection with the data that comes form the objet returned by your webservice, at the moment you are trying to convert an array collection to an array wich gives you a null array.
          • 2. Re: ArrayCollection as a Data Provider
            bitwyse Level 1
            Thanks for the reply. Can you elaborate a bit for me? As I am still new to Flex and trying to understand the framework.

            I took this code:
            <mx:ArrayCollection id="arrayOfProjects" source="{ArrayUtil.toArray(wsProjectInformation.getControlsProjects.lastResult)}"/>
            from a sample on line. . . .

            My webservice returns an array of objects, so I thought ArrayUtil.toArray did what you are saying ( to fill the array )

            Your thoughts?
            • 3. Re: ArrayCollection as a Data Provider
              HyderAlamgir Level 1
              quote:

              Originally posted by: batmitra
              Hi
              when you try to bind a dataprovider whith an array collection, you must first make an instance of that array, on the result function form the webservice, and you must fill the arraycollection with the data that comes form the objet returned by your webservice, at the moment you are trying to convert an array collection to an array wich gives you a null array.


              I've never really understood the difference between an array and an arraycollection. Could you elaborate on that too batmitra. Would really appreciate it!
              • 4. Re: ArrayCollection as a Data Provider
                batmitra Level 1
                Hi
                I can elaborate more on this of course, but i need to know in which language are you developing your webservice?

                menwhile take a look at this link , it explains the difference between Array and ArrayCollection

                Difference between Array and Array Collection
                • 5. Re: ArrayCollection as a Data Provider
                  bitwyse Level 1
                  I created the web service in Java running on a Domino 7.02 server. It returns and array of objects.