4 Replies Latest reply on Apr 9, 2008 12:42 PM by michael_teter

    dataProvider string problem

    michael_teter
      Howdy. I'm completely new to Flex (and working with Flex3).

      I've got this <mx:HTTPService id="getErrorList" .../> that's fetching XML from a little Rails app. My intent is to display the results in a DataGrid, but I'm unable to figure out the proper string for the grid's dataProvider.

      Should the dataProvider string be "{getErrorList.lastResult.xmlarraylist.xmlitem}" ?

      Here's what my data actually looks like (copied from browser output):
      <?xml version="1.0" encoding="UTF-8" ?>
      - <fixed-errors type="array">
      - <fixed-error>
      <acct>12345</acct>
      ...

      I've tried "{getErrorList.lastResult.fixed-errors.fixed-error}", but it seems hyphens are not allowed.

      I'd love suggestions or references to proper documentation on this. Since I'm so new at this, I'm not yet clear on how I can debug this to perhaps inspect "getErrorList.lastResult" at run-time... my thought was that I might be able to see the object tree and understand what the proper names for the rest would be.

      Thanks much.
      Michael
        • 1. Re: dataProvider string problem
          Gaurav J Adobe Employee
          try

          event.target.lastResult

          I believe there is a way to workaround the hyphen

          try

          event.target.lastResult["fixed-errors"]

          also take a look at

          http://livedocs.adobe.com/flex/2/langref/XML.html#includeExamplesSummary
          • 2. Re: dataProvider string problem
            ntsiii Level 3
            Don't bind directly to lastResult, it is just too hard to debug.

            Instead implement a result handler:
            <mx:HTTPService id="getErrorList" resultFormat="e4x" result="onResult(event)" .../>

            import mx.rpc.events.ResultEvent;
            ...
            private function onResult(event:ResultEvent):void {
            var xmlResult:XML = XML(event.result);
            trace(xmlResult.toXMLString());
            //once you ge valid xml here, you will be set to go.

            Tracy
            • 3. Re: dataProvider string problem
              ntsiii Level 3
              Also, to handle special characters in the xml (if you are not in control of the xml format), you can use bracket notation:

              var xml:XML = xmlResult["fixed-error"][0]; //will give first child node

              When you use brackets, omit the property "dot".

              Tracy
              • 4. Re: dataProvider string problem
                michael_teter Level 1
                I solved my problem, but these are good suggestions.

                I did two things to fix my problem (which I fixed before these replies arrived, thus my "fix" was lame :) ).

                I'm using Ruby on Rails as my back-end for this demo. My model was called "FixedErrors", which, using the super handy to_xml() function, was changing that name to "<fixed-errors><fixed-error>...</fixed-error> etc.

                I just recreated my simple model with a non-camelcase name so Rails wouldn't help me out on it :) (new model called Fixederrs).

                But my #1 problem was... I didn't realize I needed to put this in my Application definition: creationComplete="getErrorList.send();"

                Thanks for the help though!