Question

I'm using BlazeDS in Tomcat7 and Flex. I'm trying to use custom classes between the client and server. In as:

package
{
   [Bindable]
   [RemoteClass(alias="remoting.Product")]
   public class Product 
   {
      public var name:String;
      public var id:int;
      public var isVisible:Boolean;
   }
}

In Java:

package remoting;
public class Product {

    public String name;
    public int id;
    public Boolean isVisible;

    public Product(){
            name = "Product 0.1";
            id = 123;
            isVisible = false;
    }
    public void setName(String _name){
            name = _name;
    }
    public void setId(int _id){
            id = _id;
    }
    public void setVisible(Boolean _isVisible){
            isVisible = _isVisible;
    }
}

Service part:

public Product echo() {
        Product product = new Product();
        product.setId(123);
        product.setName("My Product");
        product.setVisible(true);
        return product;
}

I can successfully set the destination of the RemoteObject and call the echo() method. The result event fires up, with the Product object in event.result. However, it does not contain any sensible data. The variables from AS class just get initialized with null, 0 and true values. I'm wondering what's the problem. I tried returning a String with parameters from Product and it works fine, so they get set fine. The problem is in mapping.

I could go another way and implement Externalizable but I don't understand this part from the example:

 name = (String)in.readObject();
 properties = (Map)in.readObject();
 price = in.readFloat();

What if there is a number of strings?

Cheers.

Was it helpful?

Solution

In java class: use private fields and implement getters.

package remoting;
public class Product {

    private String name;
    private int id;
    private Boolean isVisible;

    public Product() {
            name = "Product 0.1";
            id = 123;
            isVisible = false;
    }
    public void setName(String _name){
            name = _name;
    }
    public String getName(){
            return name;
    }
    public void setId(int _id){
            id = _id;
    }
    public int getId(){
            return id;
    }
    public void setIsVisible(Boolean _isVisible){
            isVisible = _isVisible;
    }
    public Boolean getIsVisible() {
            return isVisible;
    }
}

OTHER TIPS

You could also switch from BlazeDS to GraniteDS: the latter has a powerful transparent externalization mechanism as well as code generation tools that can really save your time (see documentation here).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top