baluba
04-30-2008, 12:34 PM
- The attached code works fine. (The service code is not included, it just returns a list of the shown User objects)
- If I change the model objects User and Role to inherit from BaseModel the service call fails, the GWT Serializer complains about the Role class not being serializable...???
So, currently, if you write your own model class extending BaseModel, you can't set a property on it which holds a collection of another BaseModel class. Is this a bug or a result of GWT architecture and that RpcMap thing defined in the BaseModelData class?
The difference between a BaseModel and BaseTreeModel is that the latter has a ArrayList of children (TreeModels). So for some reason this makes the GWT rpc work.
public class RpcProblem implements EntryPoint {
static public class Role extends BaseTreeModel {
public Role() { }
public Role(String code) { set("code", code); }
}
static public class User extends BaseTreeModel {
public User() { }
public User(String username) { setUsername(username); }
public void setUsername(String name) { set("username", name); }
public void setRoles(List<Role> roles) { set("roles", roles); }
public String getName() { return (String)get("name"); }
}
public void onModuleLoad() {
Viewport viewport = new Viewport();
Button button = new Button("TestRpc", new SelectionListener() {
public void componentSelected(ComponentEvent ce) {
TestServiceAsync service = TestService.App.getInstance();
service.getUsers("whoever", new AsyncCallback() {
public void onFailure(Throwable throwable) {
Window.alert("rpc failed: " + throwable.getMessage());
}
public void onSuccess(Object o) {
List<User> users = (ArrayList<User>) o;
Window.alert("rpc succeeded, num returned: " + users.size());
}
});
}
} );
viewport.add(button);
viewport.layout(true);
RootPanel.get().add(viewport);
}
}
- If I change the model objects User and Role to inherit from BaseModel the service call fails, the GWT Serializer complains about the Role class not being serializable...???
So, currently, if you write your own model class extending BaseModel, you can't set a property on it which holds a collection of another BaseModel class. Is this a bug or a result of GWT architecture and that RpcMap thing defined in the BaseModelData class?
The difference between a BaseModel and BaseTreeModel is that the latter has a ArrayList of children (TreeModels). So for some reason this makes the GWT rpc work.
public class RpcProblem implements EntryPoint {
static public class Role extends BaseTreeModel {
public Role() { }
public Role(String code) { set("code", code); }
}
static public class User extends BaseTreeModel {
public User() { }
public User(String username) { setUsername(username); }
public void setUsername(String name) { set("username", name); }
public void setRoles(List<Role> roles) { set("roles", roles); }
public String getName() { return (String)get("name"); }
}
public void onModuleLoad() {
Viewport viewport = new Viewport();
Button button = new Button("TestRpc", new SelectionListener() {
public void componentSelected(ComponentEvent ce) {
TestServiceAsync service = TestService.App.getInstance();
service.getUsers("whoever", new AsyncCallback() {
public void onFailure(Throwable throwable) {
Window.alert("rpc failed: " + throwable.getMessage());
}
public void onSuccess(Object o) {
List<User> users = (ArrayList<User>) o;
Window.alert("rpc succeeded, num returned: " + users.size());
}
});
}
} );
viewport.add(button);
viewport.layout(true);
RootPanel.get().add(viewport);
}
}