Daniel Moura
Daniel Moura

Reputation: 7966

Accessing a java method in a flex object

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() ?

Upvotes: 0

Views: 922

Answers (1)

Cornel Creanga
Cornel Creanga

Reputation: 5308

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.

Upvotes: 1

Related Questions