From e47186cf716ba706df8f91af91a94b64b92e8cbe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Wed, 7 Dec 2011 12:58:17 +0000 Subject: [PATCH] #8035 Extra event on TextField with ActionHandler svn changeset:22284/svn branch:6.7 --- .../terminal/gwt/client/ui/VTextField.java | 13 +++++ .../textfield/MultipleTextChangeEvents.java | 57 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 tests/testbench/com/vaadin/tests/components/textfield/MultipleTextChangeEvents.java diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java index 55921bab44..5894e00349 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java @@ -587,7 +587,20 @@ public class VTextField extends TextBoxBase implements Paintable, Field, } public void onBeforeShortcutAction(Event e) { + // Remember current value to detect changes + String oldValue = valueBeforeEdit; + valueChange(false); + + /* + * The valueChange method updates valueBeforeEdit when a "text" variable + * is sent. This will cause a text change event to be simulated on the + * server. In that case, we should avoid sending the same text as a + * normal text change event. (#8035) + */ + if (oldValue != valueBeforeEdit) { + lastTextChangeString = valueBeforeEdit; + } } // Here for backward compatibility; to be moved to TextArea diff --git a/tests/testbench/com/vaadin/tests/components/textfield/MultipleTextChangeEvents.java b/tests/testbench/com/vaadin/tests/components/textfield/MultipleTextChangeEvents.java new file mode 100644 index 0000000000..62d3a1679a --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/textfield/MultipleTextChangeEvents.java @@ -0,0 +1,57 @@ +package com.vaadin.tests.components.textfield; + +import com.vaadin.event.Action; +import com.vaadin.event.Action.Handler; +import com.vaadin.event.FieldEvents.TextChangeEvent; +import com.vaadin.event.FieldEvents.TextChangeListener; +import com.vaadin.event.ShortcutAction; +import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.util.Log; +import com.vaadin.ui.AbstractTextField.TextChangeEventMode; +import com.vaadin.ui.TextField; + +public class MultipleTextChangeEvents extends TestBase { + + private final Log log = new Log(5); + + @Override + public void setup() { + TextField tf = new TextField(); + tf.setTextChangeEventMode(TextChangeEventMode.TIMEOUT); + tf.setTextChangeTimeout(500); + tf.addListener(new TextChangeListener() { + public void textChange(TextChangeEvent event) { + log.log("TextChangeEvent: " + event.getText()); + } + }); + getMainWindow().addActionHandler(new MyHandler()); + + addComponent(log); + addComponent(tf); + } + + class MyHandler implements Handler { + private static final long serialVersionUID = 1L; + Action actionenter = new ShortcutAction("Enter", + ShortcutAction.KeyCode.ENTER, null); + + public Action[] getActions(Object theTarget, Object theSender) { + return new Action[] { actionenter }; + } + + public void handleAction(Action theAction, Object theSender, + Object theTarget) { + log.log("Enter"); + } + } + + @Override + protected String getDescription() { + return "Entering something into the textfield and quickly pressing enter should only send one TextChangeEvent"; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(8035); + } +} \ No newline at end of file -- 2.39.5