加载 Resty-GWT
Loading Resty-GWT
当客户端在服务器上发送 json 时,如何显示加载小部件。
从 GWTP exmaple 的例子中我找到了这样的方法
/**
* 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时显示它发送了请求?我可以在 resty-gwt 中使用 onLockInteraction 吗?
您可以使用 RestyGWT 自定义 Dispatcher 来跟踪请求生命周期。调度程序可以手动配置或使用注释 (https://resty-gwt.github.io/documentation/restygwt-user-guide.html)。手动设置示例:
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,最后显示加载指示器。
当客户端在服务器上发送 json 时,如何显示加载小部件。
从 GWTP exmaple 的例子中我找到了这样的方法
/**
* 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时显示它发送了请求?我可以在 resty-gwt 中使用 onLockInteraction 吗?
您可以使用 RestyGWT 自定义 Dispatcher 来跟踪请求生命周期。调度程序可以手动配置或使用注释 (https://resty-gwt.github.io/documentation/restygwt-user-guide.html)。手动设置示例:
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,最后显示加载指示器。