Vaadin 7 client-to-server communications via LegacyConnector

The Vaadin 7 CKEditor add-on uses the LegacyConnector (originally built for Vaadin 6), and we’ve noticed that some events generated in the client don’t seem to appear in the server as expected.

In the client-side code, we have an onSave() callback that’s invoked by CKEditor when a save button or CTRL-S is pressed. It looks like this:

[font=courier new]
    public void onSave() {
        if ( ckEditorIsReady && ! readOnly ) {
            ignoreDataChangesUntilReady = false; // If they give us data by saving, we don't ignore whatever it is
            String data = ckEditor.getData();
            if ( ! data.equals(dataBeforeEdit) ) {
                clientToServer.updateVariable(paintableId, VAR_TEXT, data, false);\
                dataBeforeEdit = data;
            } else {
                //logState("onSave() - data has NOT changed");
            }

            clientToServer.updateVariable(paintableId, VAR_VAADIN_SAVE_BUTTON_PRESSED,"",false); // inform that the button was pressed too
            logState("onSave() - sending pending changes to the server; rpc queue count: " + clientToServer.getServerRpcQueue().size() + "; isFlushPending: " + clientToServer.getServerRpcQueue().isFlushPending());
            clientToServer.getServerRpcQueue().flush(); // ensure anything queued up goes now on SAVE
            logState("onSave() - after sent pending changes to the server; rpc queue count: " + clientToServer.getServerRpcQueue().size() + "; isFlushPending: " + clientToServer.getServerRpcQueue().isFlushPending());
        }
    }
[/font]

In the javascript console, we see our log messages that the button was pressed, and it shows the queued element (and the second ‘after sent’ log message shows isFlushPending=true with no change in the queue size). But the server’s code uses the method ‘changeVariables’ to handle the updates. What we’ve found is that clicking the editor’s SAVE button or typing CTRL-S is detected by the ‘onSave’ callback, but until we move the mouse ever so slightly over the button (or move the cursor out of the editor so the blur event also fires), we don’t see the server’s ‘changeVariables’ being called.

While sending the events from the client to the server uses the queue and a scheduled task for the javascript event loop, it’s unclear why they don’t seem to arrive at the server until we move the cursor a bit more.

You can see this on a demo system: https://open.esignforms.com/Vaadin7CKEditor/ if you click the blue disk (Vaadin Save button) icon in the second/lower editor. If you carefully click, but don’t move the mouse, the event fires as expected, but you don’t see the server responding until you move the mouse a bit.

You can also use the ‘Open Non-Model Subwindow with 100% height’ button, and then use the Save button and you will see that in this case, the event does arrive on the server right away without having to move the mouse after the click.

If you have any ideas why it might not be arriving at the server without that extra mouse move, I’d be grateful to hear back.