6 Replies Latest reply on Aug 19, 2010 12:24 AM by BhaskerChari

    Help needed in  converting ArrayList to ArrayCollection

    kiran7881 Level 1


      I am converting an ArrayList (Java) to ArrayCollection of Flex .
      Please help me in this , i dont know whether this is correct approach or not

       

      I have a Created a User VO ActionScript class  on flex with two properties as uname , pass .

       

      [Bindable]       
              var result:ArrayCollection

       

      private function displayDetails(event:ResultEvent):void
      {
      result = event.result as ArrayCollection;
      }


      <mx:DataGrid  dataProvider="{result}">
                      <mx:columns>
                          <mx:DataGridColumn headerText="UserName" dataField="uname"/>
                          <mx:DataGridColumn headerText="Password" dataField="pass"/>
                         
                      </mx:columns>
                  </mx:DataGrid>

       

      This is from my Java DAO File :


                  ResultSet rs = stmt.executeQuery("select NAME , PASS from Users");
                  list = new ArrayList();
                  while (rs.next()) {
                      User user = new User();
                      user.setUname(rs.getString(1));
                      user.setPass(rs.getString(2));
                      list.add(user);

       

                  }

       


              return list;

       

      With the below code ,the displayed DataGrid is empty with no data , please help me where i am doung wrong

       

       

       

      Do i need to do anything more ?? The data is coming well on to the lcds server console .

      Please help .

        • 1. Re: Help needed in  converting ArrayList to ArrayCollection
          BhaskerChari Level 4

          Hi Kiran,

           

           

          Try this once....

           

          private function displayDetails(event:ResultEvent):void
          {
          result = new ArrayCollection(event.result as Array);

          }

           

          Just try to debug by putting the break point and make sure that you are getting event.result as Array....If not then change your code accordingly..

           

           

          Thanks,

          Bhasker

          • 2. Re: Help needed in  converting ArrayList to ArrayCollection
            flex4 Level 2

            Hi kiran

             

                             I think this will help u ... the problem with ur code is u can not create the instance of the arraycollection..  u just left the code like this ...

             

             

                             var result:ArrayCollection;

             

                               But u need to create an object for the ArrayCollection also..

             

                                      var result:ArrayCollection = new ArrayCollection();

             

             

                                  and also one more thing user RemoteClass[alias("source of ur vo class u are using in javaside")] in the vo of ur actionscript...

             

             

             

                                         i think it wil work now....

            1 person found this helpful
            • 3. Re: Help needed in  converting ArrayList to ArrayCollection
              kiran7881 Level 1

              Hi ,

               

              I tried with the things you mnetioned , but still i am not getting data into my DataGrid . I am posting my code here .please help .


              This is the code which is giving an empty DataGrid , even though when data is coming fine on to lcds server console .please tel me what might be the wrong here , screen shot attache dof the data on to the lcds server console .

               

              package vo
              {
                 
                  [RemoteClass(alias="vo.User")]
                 
                  public class User
                  {
                     
                      public var uname:String;
                      public var pass:String;
                     
                     
                      public function User()
                      {
                      }

                  }
              }

               

              On to MXML File :

               

                 
              <mx:Form>

               

                      <mx:Button label="GetData" click="GetData()"/>

               


                          <mx:DataGrid  dataProvider="{result}">
                              <mx:columns>
                                  <mx:DataGridColumn headerText="UserName" dataField="uname"/>
                                  <mx:DataGridColumn headerText="Password" dataField="User.pass"/>
                                 
                              </mx:columns>
                          </mx:DataGrid>
                  </mx:Form>

               

              <mx:RemoteObject id="remObj2"
              destination="myJavaClass"
              fault="Alert.show(event.fault.faultString);"
              result="displayDetails(event)"
              />

               

               

                      [Bindable]       
                      var result:ArrayCollection

                      public function GetData():void
                      {
              remObj2.getData();
                      }


              private function displayDetails(event:ResultEvent):void
              {

              result = new ArrayCollection(event.result as Array);
              }

              datacomingfine.jpeg

               

              on to the java class i am just returning the ArrayList consisting of User DTO's , for example :

               

              ArrayList list = new ArrayList();

              User user = new User();

              user.setUName("Kiran");

              user.SetPass("Keyboard")

              list.add(user);

              return list ;

               

              Please help , so that i can populate the data on to DataGrid with the help of Java .Thanks in advance .

              • 4. Re: Help needed in  converting ArrayList to ArrayCollection
                BhaskerChari Level 4

                Hi Kiran,

                 

                Debugging solves most of the problems that you encounter ......you need to use a lot of debuggung so that you will come to know exactly what's

                happening indeed...

                 

                So just put a break point at your displayDetails(event:ResultEvent):void  function and try to watch the event variable and check the event.result

                 

                What is the datatype of the event.result ...Are you getting any data or is it null..???

                 

                 

                Please make these observations and let me know...

                 

                 

                Thanks,

                Bhasker

                • 5. Re: Help needed in  converting ArrayList to ArrayCollection
                  kiran7881 Level 1

                  Thanks Bhaskar , i tried to debug , but the problem is that FLEX3 Builder isn't stopping at  Break Points . please let me know do i need to install anything for debugging to work ??

                  Waiting for your reply .

                  • 6. Re: Help needed in  converting ArrayList to ArrayCollection
                    BhaskerChari Level 4

                    Hi Kiran,

                     

                    Try to install the debugging version of FlashPlayer9.

                     

                    Thanks,

                    Bhasker

                    1 person found this helpful