2017-02-19 45 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作爲參數。 –