【问题标题】:Loading Resty-GWT加载 Resty-GWT
【发布时间】:2017-07-08 17:54:54
【问题描述】:

当客户端在服务器上发送 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 一起使用吗?

【问题讨论】:

标签: gwt resty-gwt


【解决方案1】:

您可以使用 RestyGWT 自定义 Dispatcher 来跟踪请求生命周期。 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,则最终显示加载指示器。

【讨论】:

  • 这取决于您的架构,但您始终可以使用静态变量来共享 eventBus。使用 Gin,您可以创建一个 RootRestService 提供程序并将 eventBus 添加为参数。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-20
  • 1970-01-01
  • 2016-03-05
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 2016-11-14
相关资源
最近更新 更多