views:

32

answers:

1

Assume I have the following java class

public class Square {
        private Long id;

    private double sideLength;

    public void setSideLength(double sideLength) {
        this.sideLength = sideLength;
    }

    public double getSideLength() {
        return this.sideLength;
    }

    public double getArea() {
        return sideLength * sideLength;
    }

//another methods...

}

Inside an actionscript class, using RemoteObject, I invoke the java method SquareDAO.findById(Long id) an I get an Object with the following:

object.id
object.sideLength

But I don't get the area. How can I invoke the method getArea() ?

+1  A: 

When calling remote methods (from java, c#, php etc) you will receive back only the serialized properties taken from the object returned by the invoked method. If you want to invoke the method getArea from Flex you should do the following:

a)Create an ActionScript class called Square having the remote class metadata [RemoteClass(alias="yourjavapackage.Square")]

b)Add a method getArea inside your class doing the same thing like in Java.

c)Call the java method and notice that it will return back an instance of your AS class. Now you can call getArea method from AS

The remote service from BlazeDS is too complex to be explained in details in a post, I strongly suggest to invest some time reading the BlazeDS developer guide, at least the remote chapter.

Cornel Creanga
If I have to copy the method inside the AS class, every time the method changes I'll have to remember to change in both places.
Daniel Moura
Yes, it's one of the disadvantages when working with two different runtimes/languages. The combination Java applets+Java server side did not had this problem.
Cornel Creanga