3 Replies Latest reply on Oct 14, 2010 11:57 AM by JeffreyGong

    Issues in mapping objects from java to flex - using flex4

    jigarinu

      Hi,

       

      I have a class in java which i want to send to flex4 using BlazeDS as middleware. There are a few issues that i am facing and they are:

      1. When sending the object across (java to flex), the properties with boolean data type having value as true gets converted to properties with value as  false. Even after setting the value to true it still comes as false on flex side. Can't understand why this is happening.
      2. When sending the list of object containing property with boolean data type, the object on flex side does not show those properties at all. As of there were no boolean properties in that object.
      3. Last but not the least, When sending List<ContractFilterVO> contractFilterVOs to flex using remote call, the result typecasted to ArrayCollection does not show the holding objects as ContractFilterVOs but as plain default Object though having all the properties send, except the boolean one mentioned in above points. Basically it is not able to typecast the objects in arraycoolection but the same objects gets typecasted when sent individually.

      In all the above points i am using Remote Service through BlazeDS for connectivity with Java. I have done a lot of this stuff in Flex 3 but doing it for the first time in flex 4, is there anything that Flex 4 needs specific. Below is the pasted code for reference purpose.

       

      Flex Object

       

      package com.vo

      {

           [RemoteClass(alias="com.vo.ContractFilterVO")]

      public class ContractFilterVO{

           public function ContractFilterVO(){

           }

           public var contractCode:String;

           public var contractDescription:String;

           public var isIndexation:Boolean;

           public var isAdditional:Boolean;

      }

      }

       

      /**

      * Rmote Part of code

      */

       

      var remoteObject:RemoteObject = new RemoteObject();

      remoteObject.destination="testService";

      remoteObject.addEventListener(ResultEvent.Result,handleResult);

       

      public function handleResult(event:ResultEvent):void{

           var contarctFilterVOs:ArrayCollection = event.result as ArrayCollection; //Point 2&3 probelem, if list sent form java

           var contarctFilterVO:ContractFilterVO= event.result as ContractFilterVO; //Point 1 probelem, if only single Object of type ContractFilterVO sent form java

      }

       

      Java Object

       

      package com.vo

      {

       

      public class ContractFilterVO implements Serializable

       

      {

           public function ContractFilterVO(){

           }

           private static final long serialVersionUID = 8067201720546217193L;

           private String contractCode;

           private String contractDescription;

           private Boolean isIndexation;

           private Boolean isAdditional;

      }

      }

       

      I don't understand what is wron in my code on either side, it looks syntactically right. It would be great anyone could help me point out my mistake here. Waiting for right solutions...

       

      Thanks and Regards,

      Jigar

       

       

       

       

        • 1. Re: Issues in mapping objects from java to flex - using flex4
          JeffreyGong Level 1

          Hi Jagar,

           

          You need public getters and setters in your Java com.vo.ContractFilterVO.

           

          I had the same problem as item 3 in your list sometimes for Flex 4.  I solved this by putting something like new ContractFilterVO() somewhere before calling the RemotingObject.

           

          Help this will help you.

           

          Jeffrey

          1 person found this helpful
          • 2. Re: Issues in mapping objects from java to flex - using flex4
            jigarinu Level 1

            Hi Jeffery,

             

            Thanks for your reply, it did solve my query @ point 3 as well as point 2 where the objects in arraycollection were not geting converted and boolean properties did not appear when list of an objects were received. And hey, i did have public functions for properties defined java class, just forgot to mention here in post, sorry for that.

             

            The solution you gave was right, but than what if i have a VO which has multiple List of objects coming from Java, than i would have to create an instance of each type of object on flex side this is too tedious, is'nt it? Is there any better solution... out there.

             

            And jeffery do you some tricks up your sleeve for this Boolean issues to that i am facing in point 1... Still struggling with this one...

             

            Anyone out there would be more than welcome to point my mistake, if any and provide tips/tricks or solutions...

             

            Thanks again to Jeffery...

             

            Waiting for more solutions sooner...

             

            thanks and Regards,

            Jigar

            • 3. Re: Issues in mapping objects from java to flex - using flex4
              JeffreyGong Level 1

              Hi Jigar,

               

              Glad you solved point 2 and 3!  Which is almost like fixing a bug of Flex 4 from client's side although tedious.

               

              In your Flex VO, you may need to add [Bindable] like

               

              package com.vo

              {

                   [RemoteClass(alias="com.vo.ContractFilterVO")]

                   [Bindable]

                   public class ContractFilterVO{

               

                   ........

               

               

              And in your Java VO,  Could you get  "private Boolean isIndexation;" compiled?  I think it should be "boolean", all lowercase in Java.

               

              Hope you are luck again.

               

              Jeffrey