I’d like to be able to write an inline handler in GWT. For example, with RequestBuilder I can do something like this (defining the code INLINE which handles an event thats thrown):
rb.sendRequest(postData, new RequestCallback() {
@Override
public void onError(Request request, Throwable t) {
Window.alert("Failed" + t.getMessage());
}
@Override
public void onResponseReceived(Request request, Response response) {
Window.alert(response.getText());
}
});
I’d like to do the same thing with my custom callback function. And I want to pass back a custom object. Something like this:
Person p = new Person("bob smith", 34, "san francisco");
p.GetInfo("name", new PersonCallBack(){
@Override
public void onReturned(Object someData)
{
Window.alert(String.valueOf((String)someData));
}
};
p.GetInfo("age", new PersonCallBack(){
@Override
public void onReturned(Object someData)
{
Window.alert(String.valueOf((int)someData));
}
};
What I want to do is pretty simple like above, but I’m really confused by the whole GWT event/callback thing. Seems like you have to define multiple classes and interfaces and such just to pass back one piece of data. I’m looking for the absolute SIMPLEST way to do this with the least amount of code (I don’t need custom handlers but I’m willing to use something generic and just cast data). Any help would be appreciated!
Thanks!
Have a look at
AsyncCallbackmaybe?