Delayed Client -> Server RPC call when using JSNI -> Java callbacks

Hello

I’m developing a custom UI component, that heavily uses JSNI (in order to communicate with a purely JS lib). The JSNI code makes callbacks to a ServerRPC, like this:

instance.@some.package.SomeClass::someMethod()()

The problem is, that the callback isn’t handled instantly. Vaadin sends a UIDL request only, if user performs some action (moves his mouse or presses a button). This is problematic, because the RPC calls to server are made in response to JS events coming from the mentioned JS lib. Obviously current behaviour is unacceptable, because in order for my component to work properly, user would have to move his/hers mouse constantly… So here’s my question: is there a way to force an UIDL call directly after making RPC call from JS and not to wait for user input/activity?

P.S.

The component I’m developing extends a Button on a Server side and a ButtonConnector on a client side. I’ve tried to make the component immediate, but it didin’t help.

P.S. 2

It seems that the problem occurs, because I’ve implemented a custom RequestHandler. If the handler’s response is immediate, the RPCs are sent correctly. But if the request handler takes some time to complete (about 1s), the the problem occurs. It seems that the client side of Vaadin (or GWT itself) has some sort of timeout or a watcher, that decided wether tle UIDL request is to be sent or not…

the current event chain is as described below:

  1. The JS lib performs a request, that is processed by my custom RequestHandler
  2. When the above request is complete, JS lib throws an event
  3. In response to above event, a callback is being made to the server through JSNI (RPC through an UIDL request)
  4. In response to the above RPC call the server side manipulates the UI components and sends the effects of those manipulations as a response.

Again, if the request handler sends the response immediately, everything works as expected. The problem occurs, when the processing time is longer…

Temporarily fixed the issue by dispatching an artificial MouseMove event on Body element, after the RequestHandler is done (response has been sent). When I come up with a better solution, I’ll change that ugly workaround, but for the time being it has to suffice.

I’ve had a similiar problem, an RPC call triggered from my jQuery click event handler (within JSNI method) had not actually been performed until some user action occurred, such as a mouse move.

In my case getConnection().getHeartbeat().send(); has done the trick (i.e. has forced sending a pending UIDL call).

Hi,

Recently I’ve been struggling with the same problem. UIDL request delayed and sent after user input change mouse moved or key pressed.
I’m also calling methods on Java coded objects by using JSNI and in those methods I’m calling Client to Server RPCs.

Good news is that I’ve found solution for our problem. The missing piece is the GWT $entry() function. You have to pass your JSNI method call as parameter of this function. It ensures that your code is executed within GWT context with all the exception handling stuff and pumps. So the user idle state is detected properly and UIDL requests are sent if there are any pending RPC calls.

Link to GWT Dev Guide:
http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html

Example of use:

public native void exportAdd() /*-{
    var that = this;
    $wnd.add = $entry(function(amt) {
      that.@mypackage.Account::add(I)(amt);
    });
}-*/;

Regards,
Peter