Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I resolved this issue by creating an util class for ajax calls. This class contains a <b>loadingIndicator</b> and a <b>callstaack</b>. The <b>loadingIndicator</b> is the <b>PopupPanel</b> that will display the message. The <b>callstack</b> is a static list that contains all the actual <b>AsyncCallback</b> objects that need a loading indicator. When the callback happens (success or error) the callback is removed from the list. The loading indicator will be hidden only if there is no callback left in the list.</p> <pre><code>public class Ajax { private static final PopupPanel loadingIndicator = WidgetFactory.createLoadingPopup(); private static final List&lt;AsyncCallback&lt;?&gt;&gt; callstack = new ArrayList&lt;AsyncCallback&lt;?&gt;&gt;(); public static &lt;T&gt; AsyncCallback&lt;T&gt; call(final AsyncCallback&lt;T&gt; callback) { if(!loadingIndicator.isShowing()){ loadingIndicator.center(); } callstack.add(callback); return new AsyncCallback&lt;T&gt;() { @Override public void onFailure(Throwable caught) { handleReturn(); callback.onFailure(caught); } @Override public void onSuccess(T result) { handleReturn(); callback.onSuccess(result); } private void handleReturn(){ callstack.remove(callback); if(callstack.size() &lt; 1) { loadingIndicator.hide(); } } }; } } </code></pre> <p>And then I use it for evervry RPC calls that needs a loading indicator like this:</p> <pre><code>myService.myMethod(Ajax.call(new AsyncCallback&lt;MyReturnType&gt;() { @Override public void onFailure(Throwable caught) { ... } @Override public void onSuccess(MyReturnType result) { ... } })); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload