'Out of sync' - Clicklistener and Handler on same Panel

The example below throws an ‘Out of sync’ error, when the focus is on the ‘Close’-Button and ‘ENTER’ is pressed.
The problem:
The method AbstractCommunicationManager.handleVariableBurst is called two times. The weird behaviour doesn’t occur, when the Thread sleeps a short period of time before the Tab is closed.

System used: Linux / Windows with Firefox Version 3.6 / 3.5.
With other browsers (Chrome, IE7 / 8 and Firefox 4 beta) the error does not occur.


Burst called with 837PID6heighti1680PID6widthi0PID13citruePID15stateb
OWNER FOR PID6 = class org.berlinger.vaadin.OutOfSyncExampleWindow
OWNER FOR PID13 = class com.vaadin.ui.TextField
OWNER FOR PID15 = class com.vaadin.ui.Button
--- close tab ---

Burst called with PID15PID9actiontargetp1PID9actions
OWNER FOR PID9 =  - null - 
23.02.2011 17:11:28 com.vaadin.terminal.gwt.server.AbstractCommunicationManager handleVariableBurst
WARNUNG: Warning: Ignoring variable change for non-existent component, VAR_PID=PID9
OWNER FOR PID9 =  - null - 
23.02.2011 17:11:28 com.vaadin.terminal.gwt.server.AbstractCommunicationManager handleVariableBurst
WARNUNG: Warning: Ignoring variable change for non-existent component, VAR_PID=PID9

The output above shows, that PID9 has no owner - as the Tab (Panel) is removed by the first call sent by browser.
I verified that, the owner of PID9 should be the class PanelWithHandler.


package example.outofsync;

import com.vaadin.Application;
import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.event.ShortcutAction;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Form;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Window;


public class OutofsyncApplication extends Application {
    @Override
    public void init () {
        Window mainWindow = new Window("Outofsync");
        Button openTestWindow = new Button("Open Test Window", new ClickListener() {
            public void buttonClick (ClickEvent event) {
                getMainWindow().addWindow(new OutOfSyncExampleWindow());
            }
        });
        mainWindow.addComponent(openTestWindow);
        setMainWindow(mainWindow);
    }


    /** */
    public class OutOfSyncExampleWindow extends Window implements Handler, ClickListener {
        private Form form;
        Action m_actionOk = null;

        /** */
        public OutOfSyncExampleWindow() {
            setWidth(400, UNITS_PIXELS);
            setHeight(200, UNITS_PIXELS);
            m_actionOk = new ShortcutAction("Default key", ShortcutAction.KeyCode.ENTER, null);

            Button closeButton = new Button("Close", (ClickListener) this);
            closeButton.focus();
            form = new Form();
            form.addField("test", new TextField("Foo"));
            form.getFooter().addComponent(closeButton);

            addComponent(form);
            addActionHandler(this);
            center();
        }

        /** */
        public void buttonClick (ClickEvent event) {
            close();
        }

        /** */
        public Action[] getActions (Object target, Object sender) {
            if (sender == this)
            {
                return new Action[] {m_actionOk};
            }
            return null;
        }

        /** */
        public void handleAction (Action action, Object sender, Object target) {
            if (action == m_actionOk) {
                close();
            }
        }
    }        
}

Is this a bug or a limitation? Is there a way to prevent this problem?
The same Message is thrown, if the class PanelWithHandler is implemented as a sub Window, closed by pressing Enter on the Close Button.

Tested the example the latest 6.5 version, could not see any “Out of Sync” errors. Either it is something that was fixed ( fixes that might be related are in 6.5.1) or it is because I removed the " VaadinApplication.getInstance().logout();" row which caused it not to compile.

Thank you for trying out the example. I have changed the example above (drop the logout() facility) and embedded it in a ready to run application. The effect mentioned, only occurs, if the Window closed, is not the main window. I use also the latest Vaadin Version 6.5.1. The weird thing is, that ‘Out of sync’ in most cases occurs, but not always. As said, if I debug the behaviour or I let the Thread sleep a little bit, the error does not occur.

The aim is, that every Button can be triggered by the Enter Key or by a mouse click. If the focus is on any Textfield, the default Button is fired. To achieve this behaviour, I have to use an Action Handler and a Clicklistener on a Button.


Could somebody take the example above and execute it?

For me, it looks like firefox sends the click event first and as the browser gets the answer so fast, it also fires the Key Event Enter. Within the internal firm network, I get this error, as the connection is very fast. On lower connection speeds, the error does not occur.

Hi all,

I am facing the same problem in a larger application.
The out of sync error occurs only on Firefox. I also tried
the example above and it is reproducible with Firefox 3.x

A workaround would be to wait for some milliseconds in the “buttonClick”
method, but I think it is an ugly workaround, since you have to
put some Thread.sleep in each method and it slows down the
application (even if it is only some millis)

Is it a known bug or is there another
way of achieving the same behavior?!

Thanks for any suggestions
Agim

I changed the example, can you test it again?

component.removeClickShortcut();