Default AsyncCallback in GWT
Doing my app, I got bored from always implement the same default error treatment (show a message, caught.printstacktrace开发者_JS百科 and etc..) in the asynccallback onfailure.
I wonder if you can make a generic treatment or standard treatment, something like that.
Thanks.
I assume you are using standard GWT-RPC. Something like this might help
public abstract class AbstractCallBack<T> implements AsyncCallback<T>{
@Override
public void onFailure(Throwable caught) {
//Default error Handling code goes here
}
}
And whenever you use your service instead of instantiating an AsyncCallback you can instantiate this class and have generalized error handling.
SomeServiceAsync service = GWT.create(SomeService.class);
service.someMethod("Hello!", new AbstractCallBack<String>() {
@Override
public void onSuccess(String result) {
// TODO Auto-generated method stub
}
});
精彩评论