9 Replies Latest reply on Dec 14, 2009 1:57 AM by Shivik

    How to convert RemoteObject results to AS VOs

    Shivik

      Hello all

       

      I am referring the screencast by Wade Arnold to implement type mapping in my zend project using zend_amf and flex app.

       

      As described in the tutorial, I got the type displayed in Charles proxy sniffer in the AMF response. The result object UserVO in php is mapped to com.vo.UserVO in flex. Now in my actionscript code, I am trying to convert the result to vo object class like this...

       

       

      public function resultHandler( resultEvent:ResultEvent):void
      {
           mx.controls.Alert.show( resultEvent.result.toString ); // this displays [object Object]
           mx.controls.Alert.show( resultEvent.result.username ); // this displays the username field from server
           
           var user:UserVO = resultEvent.result as UserVO; // converting the result to vo
           mx.controls.Alert.show( user.username );  // this gives an error, gives null object
      }

       

       

      Can somebody help me out over here? How can I convert the result received from server to AS object?

       

      Thanks and Regards
      ShiVik

        • 1. Re: How to convert RemoteObject results to AS VOs
          435.mahesh Level 1

          Store eventResult data into ArrayCollection and covert that as corresponding valueobject like

            Employee e=new Employee();

            e.name=acid.getItem().name.;

            e.address=acid.getItem().address;

            put these in loop.Now u will get the data in Valueobject(Employee).

           

           

           

           

           

           

           

          Regards

          D.Mahesh Babu

          • 2. Re: How to convert RemoteObject results to AS VOs
            PhilipKeiter Level 2

            D.Mahesh,

             

            According to the video he linked, he should be able to type cast it without setting the properties individually.

             

            ShiVik,

             

            I assume you set the mappings in PHP (and in the correct order)?

             

            Thanks,

            Philip

            • 3. Re: How to convert RemoteObject results to AS VOs
              Shivik Level 1

              Hello there.

               

              The solution that you have suggested is the workaround I am already using. Although there is no need to use the ArrayCollection.

               

              I am doing it like this...

               

              public function resultHandler( event:ResultEvent):void
              {
                   UserVO e = new UserVO();
                   e.name = event.result.username.;
                   e.address = event.result.password;
              }
              

               

              Although storing the result in ArrayCollection may help when using DataGrid. But that is beyond the scope of this topic.

               

              I have the problem that the VOs on server side and flex side are both strongly typed, they are set to be mapped. But still are not being mapped.

               

              The answer should be this....

               

              public function resultHandler( event:ResultEvent ):void
              {
                   UserVO e = result.event as UserVO;
              }
              

               

              Here are the VOs I have created on both php and flex sides...

               

              // UserVO.php
              <?php
              class UserVO
              {
                   var $username = "";
                   var $password = "";
                   var $_explicitType = "com.vo.UserVO";
              }
              

               

              // com/vo/UserVO.as
              package com.vo
              {
                   [RemoteClass(alias="UserVO")]
                   [Bindable]
                   public class UserVO {
                        public var username:String;
                        public var password:String;
                   }
              }
              

               

              Thanks and Regards

              ShiVik

              • 4. Re: How to convert RemoteObject results to AS VOs
                PhilipKeiter Level 2

                ShiVik,

                 

                So your server mapping looks like this then?

                 

                $server->setClassMap("UserVO","UserVO");

                 

                and you have the DAO in there?

                 

                I wonder if maybe it gets confused when they have the same name. That would explain why the guy in the video named them differently on the Flex side than on the PHP side.

                 

                Thanks,

                Philip

                1 person found this helpful
                • 5. Re: How to convert RemoteObject results to AS VOs
                  435.mahesh Level 1

                  Shisvik

                  I think u have set like this

                    alias="com.vo.UserVO";

                   

                   

                   

                   

                   

                   

                  Regards

                  D.Mahesh Babu

                  • 6. Re: How to convert RemoteObject results to AS VOs
                    Shivik Level 1

                    Hello there Peter

                    So your server mapping looks like this then?

                     

                    $server->setClassMap("UserVO","UserVO");

                    Actually no. My server mapping looks like this....

                     

                    $server->new Zend_Amf_Server();
                    $server->addDirectory( APPLICATION_PATH . '/services/' );
                    $server->addDirectory( APPLICATION_PATH . '/vo/' );
                    echo $server->handle();
                    

                     

                    So this way I don't need to write the setClassMap separately for every VO and service. I don't know whether this addDirectory method is there in AMFPHP or not, but since Wade Arnold worked both AMFPHP and Zend_AMF, so it could be there.

                     

                    Could this be the reason of my problems? Its finding the services and vo correctly though.

                     

                    Thanks and Regards

                    ShiVik

                    • 7. Re: How to convert RemoteObject results to AS VOs
                      Shivik Level 1

                      @ D. Mahesh

                       

                      I think u have set like this

                      alias="com.vo.UserVO";

                      I have to set this alias in my php VO?

                       

                      Thanks and Regards

                      ShiVik

                      • 8. Re: How to convert RemoteObject results to AS VOs
                        Shivik Level 1

                        Please follow this topic over at Nabble Zend Forum for a better look at my problem.

                         

                        Thanks and Regards

                        ShiVik

                        • 9. Re: How to convert RemoteObject results to AS VOs
                          Shivik Level 1

                          Hello all

                           

                          I have been finally able to solve this problem. The problem was that addDirectory method only which I used for lazy-loading of classes. I used the setClassMap and it worked. Although addDirectory is so much better - O lazy loading! I'll miss you! Sorry for exaggerating my joy.

                           

                          Thanks and Regards

                          ShiVik