2017-02-19 116 views
0

当客户端在服务器上发送json时,如何显示加载小部件。加载Resty-GWT

从例如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,当它发送的请求?我可以使用onLock互动与resty-gwt吗?

+1

不确定关于GWTP,但也许这个http://stackoverflow.com/a/38392507/5612847将有用。 –

回答

1

您可以使用RestyGWT自定义分派器来跟踪请求生命周期。分派器可以手动配置或使用注释(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.

+0

我该如何叫事件?我在这里没有主持人 – LeshaRB

+0

这取决于您的架构,但您始终可以使用静态变量来共享eventBus。使用Gin你可以创建一个RootRestService提供者并添加eventBus作为参数。 –