4 Replies Latest reply on Feb 5, 2007 2:49 PM by swickes

    How do I populate a datagrid with a web service result that is an array?

    swickes Level 1
      I know how to populate a datagrid using a CF web service that returns a query result. But what if I want my CF component to run a query, then massage the data and return- not a query- but an array from the web service.

      Seems like, because my two dimensional ColdFusion array has no column names, I must create name-value pairs either on the CF side or the Flex side. BTW I prefer to use mx:webservice and not remoteObject.

      Any ideas on how best to populate a datagrid from an array?

      Thanks.
        • 1. Re: How do I populate a datagrid with a web service result that is an array?
          Robert S Level 1
          You can create the default dataprovider type for the datagrid (ArrayCollection) as follows:

          var ac:ArrayCollection = new ArrayCollection(YourDataAsArray);
          • 2. Re: How do I populate a datagrid with a web service result that is an array?
            swickes Level 1
            Thanks for your response.

            Since writing my first post, I have learned that I cannot simply return the 2 dimensional array I create in my CFC. I think I need to return an array of structures.

            So now the question is, how do a receive an array of structures and stick it into an arrayCollection?

            I get this error:
            TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection@3ce1251 to Array.

            in this function:
            [Bindable]
            public var acPeriod:ArrayCollection;

            private function wsListResult(event:ResultEvent):void{ acPeriod= new ArrayCollection(wsList.onePeriod.lastResult);
            }
            • 3. Re: How do I populate a datagrid with a web service result that is an array?
              swickes Level 1
              Thanks for your response.

              Since writing my first post, I have learned that I cannot simply return the 2 dimensional array I create in my CFC. I think I need to return an array of structures.

              So now the question is, how do a receive an array of structures and stick it into an arrayCollection?

              I get this error:
              TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection@3ce1251 to Array.

              in this function:
              [Bindable]
              public var acPeriod:ArrayCollection;

              private function wsListResult(event:ResultEvent):void{ acPeriod= new ArrayCollection(wsList.onePeriod.lastResult);
              }
              • 4. Re: How do I populate a datagrid with a web service result that is an array?
                swickes Level 1
                (Sorry about the previous double-post).

                A colleague found the answer for me. I hope this saves someone else from 5 days of anquish!!

                When a ColdFusion component returns an array of stuctures (not a query result), recasting the array as an arrayCollection throws an error.

                THIS DOES NOT WORK:
                acSpeeds= new ArrayCollection(wsSpeeds.oneNode.lastResult);

                THIS WORKS!
                acSpeeds= wsSpeeds.oneNode.lastResult;

                It seems as though a ColdFusion-generated array of structures is already an "official" arrayCollection!!

                Hope this helps someone.