2 Replies Latest reply on Jul 26, 2010 10:51 PM by kiran7881

    Getting  ArrayCollection as null when getting data from the Remote Object using  Java .

    kiran7881 Level 1

      Hi ,

      I am using FLEX and Java Combination for a Search operation .

       

      I am able to get data into my Java DAO class which i am testing it by using System.out.println statements .

       

      I am trying to use this ArrayCollection as a DataProvider for a Datgrid , but unfortunately i am getting null

      Java Code :

       

      From the DAO class in java , i am storing some data in ArrayList  as shown :

      String sql = "Select Name , Password from Users"

      ArrayList list = new ArrayList();

      while(rs.next())
      {
      User user = new User();
      user.setName(rs.getString(1));
      user.setPassword(rs.getString(2));
      list.add(user);
      }

      return list ;

       

      Inside FLEX :

       

      public var userList:ArrayCollection;


      public function ResultHandler(event:ResultEvent):void

      {
      userList = (event.result as ArrayCollection);   
      }

      Please help how to resolve this . I am confused as this is not going into the FaultEvent so i guess there is no Exception with this .

       

      Need your suggestions to resolve this .

      Thanks in advance .

        • 1. Re: Getting  ArrayCollection as null when getting data from the Remote Object using  Java .
          JohanVelthuis Level 1

          Hi,

           

          I'm not familiar with the java part, but I use a similar situation with xml files webservice.

           

          usually you have to do something like this:

          var ac:ArrayCollection = event.result.list.user as ArrayCollection

           

          then there is another issue if there is no result or only one result.

          I usually do something like this:

           

          var ac:ArrayCollection = new ArrayCollection();

          if(event.result && event.result.list && event.result.list.user && event.result.list.user is ArrayCollection){

               ac = event.result.list.user as ArrayCollection

          }else if (event.result && event.result.list && event.result.list.user && event.result.list.user is ObjectProxy){

               //this happens if there's only one result

               ac.addItem(event.result.list.user);

          }else{

               trace("no results");

          }

           

          I hope this helps. For troubleshooting you can put a trace line at the top of your resulthandler function and set a breakpoint to it. Then check your Variables window for event.result and look inside  for it's children and see what type of data that is.

          • 2. Re: Getting  ArrayCollection as null when getting data from the Remote Object using  Java .
            kiran7881 Level 1

            Thank you very much for your time . I will try this .