Is it possible to seamlessly display an ajax spinner for every GWT RPC call?
I have a GWT application that uses开发者_开发技巧 RPC calls heavily. I would like to display a spinner icon whenever a call is in progress. It is easy enough to display the icon, but I want to do it seamlessly in one place so I don't have to explicitly hide and show the icon for each call.
I guess I am looking for something similar to jQuery's ajaxStart and ajaxStop events.
Has anyone done something like this before?
Cheers Tin
Why don't you implement this behaviour in a concrete implementation of AsyncCallback and subclass all the AsyncCallbacks from this one. Alternatively you could use a decorator pattern where you use a regular AsyncCallback and decorate it with another one that shows/hides the popup.
Alternatively, if you use a Command Pattern, you could just add these events to your command pattern implementation and you can register a handler that shows/hides a popup every time a request is send/received.
In response to comments that suggest a Decorator is not enough.
abstract class AbstractAsyncCallback <T> implements AsyncCallaback <T>
{
public AbstractAsyncCallback ()
{
Foo.showIcon();
}
@Override public void success (T t)
{
doSuccess(t);
Foo.hideIcon();
}
@Override public void failure ()
{
doFailure();
Foo.hideIcon();
}
public abstract void doSuccess (T t);
public abstract void doFailure (T t);
};
精彩评论