5 Replies Latest reply on Oct 12, 2009 7:11 AM by 2191925#2191925

    Get an array from Java

    quebequiano Level 1

      Hi!

       

      I define a object in Java. Its name is User.

       

      public class user....{

           private name;

           private id,

           ................

       

           ................

       

           ...............

       

      }

       

      And its equivalen in action script (with the same attributes).

       

      My question is.... What i have to do to get an Array of User (from Java) as a Array of User in Flex.

       

      I've already made a the function to send the date... now i need to know how to get them in Java.

        • 1. Re: Get an array from Java
          Gregory Lafrance Level 6

          You may be able to use HTTPService or RemoteObject:

           

          http://giantflyingsaucer.com/blog/?p=10

           

          http://learn.adobe.com/wiki/display/Flex/Flex+and+Java

           

          If this post answers your question or helps, please mark it as such.

          • 2. Re: Get an array from Java
            Ashudeep Sidana Level 1

            You can do it by using Remote Object .

             

            In remoting-config.xml you need to specify the properties , which has class name (id) and the path of the class

             

             

             

             

            <

             

            destination id="userInfo">

             

             

            <properties>

             

             

                 <source>user.UserInfo</source>

             

             

            </properties>

             

             

            </destination>

             

            This UserInfo Class will contain a method which will return the User Object .

             

            At flex side you need to call that by RemoteObject  as follows:

             

             

            <mx:RemoteObject

             

            id="remoteObject" destination="userInfo" >

                 <mx:method

             

            name="getUserInfo" result="getUserInfo_Result(event)" fault="onFault(event)" />

            </mx:RemoteObject>

             

            method would be the java class method which would return your object.

            result would be  the method where u will get the result returned from the method

            fault would be the method where u would get the error if the result is not returned.

             

            And the implementation of the getUserInfo_Result(event) goest like

             

             

             

             

             

             

             

             

            private

             

             

            function getUserInfo_Result(event:ResultEvent):void{

                 user:Object  = event.result  as Object;

            }

             

            U can make this user object as public variable so u can use it any where in ur application.

             

             

            Hope it helps..

            • 3. Re: Get an array from Java
              quebequiano Level 1

              Yes, i know that.

               

              I'm already using Remote Objects. My question is about the format of the reception in Flex.

               

              I send the objects (as a <List>Users) from Java.

               

              And i tried to get them in flex:

               

              list:ArrayCollection=ArrayCollection(event.result).

               

              But I want to have a vector of User.

               

              How can i do it?

              • 4. Re: Get an array from Java
                Ashudeep Sidana Level 1

                I dont think there is "Vector" in Flex , u can get that in Array .

                1 person found this helpful
                • 5. Re: Get an array from Java
                  2191925#2191925

                  Hi,

                   

                  I am not even getting Object Array in Flex.

                   

                  I am returning Object Array from java. I want to use that in Flex through Remote Object Mechanism.

                   

                  Could you please expain me steps from staring.

                   

                  even i tried the same syntax in flex what you suggested i.e

                   

                  function getUserInfo_Result(event:ResultEvent):void{

                   

                   

                       user:Object  = event.result  as Object;

                  }

                   

                  afetr this ichecked

                   

                  if(user as object){

                  Alert.show('it is object');

                  }

                   

                  I am not getting any Alert message.

                   

                  Also i tried

                   

                  function getUserInfo_Result(event:ResultEvent):void{

                  list:ArrayCollection=ArrayCollection(event.result)

                  }

                   

                  it is also not working.

                   

                  Please help me.

                   

                  Thanks & Regards,

                  Praveen