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"?>



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






      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");


           remoteObj.channelSet = cs;






      public function writeToConsole():void {


      "hello from Flash client");



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







      // private var returnedVal:String;








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



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






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









      Java code

















           public SimpleRemoteObject(){










      class SimpleRemoteObject {




           public void writeToConsole(String msg) {


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






           public String setName(){


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



                return "Name changed in Java";







      And I have configured destination in  remote-config.xml


      <destination id="sro">





      Please help me .

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

          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"/>



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