4 Replies Latest reply on May 11, 2007 1:15 AM by lasek86

    cant get the result properly

    lasek86
      Hi,
      Im running flex server which connects through java to mysql database.
      From Flex im running a java class which is run correctly [i know becouse i create a file in this method and after running flex app that file is being created]. That method returns List which is not empty.

      when i try to process the data like this :

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="100%">

      <mx:RemoteObject id="srv" destination="availability" fault="handleFault(event)"/>

      <mx:Panel x="336.5" y="10" width="331" height="200" layout="absolute" title="Check availability" id="panel1">
      <mx:Form x="10" y="10" width="291" height="100">
      <mx:FormItem label="Postcode" required="true">
      <mx:TextInput id="postcode"/>
      </mx:FormItem>
      </mx:Form>
      <mx:Button x="10" y="118" label="Check Availability" width="291" height="32" click="srv.checkAvailabilityForPostcode(postcode.text)"/>
      </mx:Panel>
      <mx:DataGrid x="336.5" y="218" dataProvider="{srv.checkAvailabilityForPostcode.lastResult}" width="331"/>
      </mx:Application>

      i dont get any data in Datagrid.

      When im doing this :
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="100%">
      <mx:Script>
      <![CDATA[
      import mx.rpc.events.AbstractEvent;
      import mx.rpc.events.ResultEvent;
      import mx.rpc.events.FaultEvent;
      import mx.controls.Alert;
      import mx.rpc.remoting.RemoteObject;
      import mx.utils.ArrayUtil;

      private function handleResult(event:ResultEvent):void{
      var products:Array;
      products = new Array(ArrayUtil.toArray(event.result));
      Alert.show(products[0].toString());
      }

      private function handleFault(event:FaultEvent):void{
      mx.controls.Alert.show(event.fault.faultString,"ERRRRROORR!!");
      }

      ]]>
      </mx:Script>

      <mx:RemoteObject id="srv" destination="availability" result="handleResult(event)" fault="handleFault(event)"/>
      <mx:Panel x="336.5" y="10" width="331" height="200" layout="absolute" title="Check availability" id="panel1">
      <mx:Form x="10" y="10" width="291" height="100">
      <mx:FormItem label="Postcode" required="true">
      <mx:TextInput id="postcode"/>
      </mx:FormItem>
      </mx:Form>
      <mx:Button x="10" y="118" label="Check Availability" width="291" height="32" click="srv.checkAvailabilityForPostcode(postcode.text)"/>
      </mx:Panel>
      <mx:DataGrid x="336.5" y="218" dataProvider="{srv.checkAvailabilityForPostcode.lastResult}" width="331"/>
      </mx:Application>

      i also dont get any data in the dataGrid but in the handleResult i do get three objects. What should i do to process that data ?

        • 1. Re: cant get the result properly
          dimival Level 1
          You should bind your dataprovider property to the products array you have inside ur handler, so declare it outside the handler and inside the handler assign it to the event.result property.

          Example:

          [Bindable]
          public var products:Array; //don't forget the bindable metadata

          private function resultHandler(event):void
          {
          products = event.result //the arrayUtils thing goes here
          }

          <mx:DataGrid dataprovider="{products}"/>
          • 2. Re: cant get the result properly
            lasek86 Level 1
            Thanks, that worked.. now i do have data in my datagrid.

            But now - im returning a list of objects [ List<Prodcuts> ] .... and when i recive it and copy them into my products:Array all 3 objects on that list are in products[0] ?? why ?

            private function handleResult(event:ResultEvent):void{
            products = new Array(ArrayUtil.toArray(event.result));
            }

            thats how i copy the results.
            And also i assume you have to tell actionscript what kind of objects that list contains ? becouse currently in my products:Array in products[0] there is only : [object Object],[object Object],[object Object] ... do i have to construct actionScript class which will be some kind of a bridge between java class and my flex app ? Where can i read about this ?

            Thanks in advance
            • 3. Re: cant get the result properly
              dimival Level 1
              I think that you should do something like:

              products = event.result.toArray(); //maybe FlexBuilder won't recognize the toArray() method but you don't mind FlexBuilder :P
              or
              products = event.result as Array;

              The problem is that you are creating a new Array and passing it another Array, so you are doing a list of lists, an array of arrays
              products = new Array(ArrayUtil.toArray(event.result)); // Creates a new Array which first element is another Array

              And yes, you need equivalent ActionScript classes for your Java classes, i suggest you to read the Developers Guide, there's a section called Mapping Java Classes to ActionScript classes (something like that :P).

              Hope this helps you out
              • 4. Re: cant get the result properly
                lasek86 Level 1
                Thnks a lot!! that bug was really silly... but flexBuilder really isnt helping.