1 Reply Latest reply on Aug 1, 2009 12:15 AM by Nishant28

    Remote Object - not able to get the returned value from java method

    Shivakumar Nekar

           Hi ,

       

      I am developing one sample flex aplication that connects to the java code and displays the returned value from the

      java method in flex client. Here I am able to invoke the java method but not able to collect the returned value.

      lastResult is giving null .  I am able to see the sysout messages in server console.

       

      I am using flex 3.2 and blazeds server  and java 1.5

       

      Here is the code what I have written.

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:WindowedApplication

       

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF" initialize="initApp()">

       

       

      <mx:Script>

      <![CDATA[

       

      import mx.controls.Alert;

       

       

      import mx.binding.utils.ChangeWatcher;

       

      import mx.rpc.events.ResultEvent;

       

      import mx.messaging.*;

       

      import mx.messaging.channels.*

       

       

      public function initApp():void {

       

           var cs:ChannelSet = new ChannelSet();

       

           var customChannel:Channel = new AMFChannel("my-amf", "http://localhost:8400/blazeds/messagebroker/amf");

           cs.addChannel(customChannel);

           remoteObj.channelSet = cs;

      }

       

       

       

       

      public function writeToConsole():void {

           remoteObj.writeToConsole(

      "hello from Flash client");

       

       

           var returnedVal:String = remoteObj.setName().lastResult;

           Alert.show(returnedVal);

      }

       

       

      //[Bindable]

       

      // private var returnedVal:String;

       

      ]]>

       

      </mx:Script>

       

       

       

      <mx:RemoteObject id="remoteObj" destination="sro" />

       

       

      <mx:Form width="437" height="281">

       

      <mx:FormItem>

       

      </mx:FormItem>

       

      <mx:Button label="Write To Server Console" click="writeToConsole()"/>

       

       

      </mx:Form>

       

      </mx:WindowedApplication>

       

       

      ---------------------------------------------------------------

      Java code

      ----------------------------------------------------------------

       

       

       

       

       

       

       

       

       

       

       

      public

       

       

       

           public SimpleRemoteObject(){

       

       

                super();

           }

       

       

       

       

       

      class SimpleRemoteObject {

       

       

       

           public void writeToConsole(String msg) {

                System.

      out.println("SimpleRemoteObject.write: " + msg);

           }

       

       

       

       

           public String setName(){

                System.

      out.println("Name changed in Java");

       

       

                return "Name changed in Java";

           }

      }

       

       

      -----------------------------------------------------

       

      And I have configured destination in  remote-config.xml

       

      <destination id="sro">
         <properties>    
          <source>SimpleRemoteObject</source>
          <scope>application</scope>
         </properties>
        </destination>

       

      -------------------------------------------------------------

       

       

      Please help me .

        • 1. Re: Remote Object - not able to get the returned value from java method
          Nishant28 Level 1

          You are not able to get the returned value because if you see the Remote object help you will realise you have to use result="resultfn()" and fault = "faultfn()"

           

          In this you define what you wish to do.

          More importantly in the remote object you need to define which method you wish to call using the method class like this

           

          <mx:RemoteObject id="remoteObj" destination="sro" result="r1" fault="f1"  >

               <Method name="javaMethodName" result="r2" fault="f2"/>

          <mx:RemoteObject>

           

          r2 is the function where you get the result back from java and can use it to send the alert.