当客户端在服务器上发送json时,如何显示加载小部件。
从GWTP例子中的例子我发现了这样的方法
/**
* We display a short lock message whenever navigation is in progress.
*
* @param event The {@link LockInteractionEvent}.
*/
@ProxyEvent
public void onLockInteraction(LockInteractionEvent event) {
getView().setLoading(event.shouldLock());
}
如何在加载resty-gwt时显示何时发送请求?我可以将 onLockInteraction 与resty-gwt一起使用吗?
答案 0 :(得分:1)
您可以使用RestyGWT自定义Dispatcher来跟踪请求生命周期。可以手动配置Dispatcher,也可以使用注释(https://resty-gwt.github.io/documentation/restygwt-user-guide.html)配置Dispatcher。手动设置示例:
RootRestService rest = GWT.create(RootRestService.class);
((RestServiceProxy) rest).setDispatcher(new DefaultDispatcher() {
@Override public Request send(Method m, RequestBuilder rb) throws RequestException {
RequestCallback callback = rb.getCallback();
rb.setCallback(new RequestCallback() {
@Override public void onResponseReceived(Request req, Response res) {
log.info("request success (stop event)");
callback.onResponseReceived(req, res);
}
@Override public void onError(Request req, Throwable ex) {
log.info("request error (stop event)");
callback.onError(req, ex);
}
});
try {
log.info("request initialized (start event)");
return request = super.send(m, rb);
} finally {
log.info("request fail to initialize error (stop event)");
}
}
});
您可以使用eventBus发送事件,而不是记录日志,并使用此事件来跟踪活动请求的数量,如果活动请求的数量大于0,则最后显示加载指示符。