summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2012-11-05 14:00:21 +0200
committerVaadin Code Review <review@vaadin.com>2012-11-05 14:32:28 +0000
commit1746dff124c644f4348ccf3ecf55d250a8869d75 (patch)
tree8b1a34d61bc3e137019fefefafe706152c63f9ef
parent282fbd32a1deb70565be0ed4718c3ee29d26651d (diff)
downloadvaadin-framework-1746dff124c644f4348ccf3ecf55d250a8869d75.tar.gz
vaadin-framework-1746dff124c644f4348ccf3ecf55d250a8869d75.zip
10030 Button.DisableOnClick not working properly
Change-Id: I0514bc4da186360a84d9cdb48140245108847115
-rw-r--r--client/src/com/vaadin/client/ui/button/ButtonConnector.java8
-rw-r--r--server/src/com/vaadin/ui/Button.java15
-rw-r--r--uitest/src/com/vaadin/tests/components/button/ButtonDisableEnableOnClick.html128
-rw-r--r--uitest/src/com/vaadin/tests/components/button/Buttons3.java16
4 files changed, 163 insertions, 4 deletions
diff --git a/client/src/com/vaadin/client/ui/button/ButtonConnector.java b/client/src/com/vaadin/client/ui/button/ButtonConnector.java
index 546bdecb61..c3aa66b285 100644
--- a/client/src/com/vaadin/client/ui/button/ButtonConnector.java
+++ b/client/src/com/vaadin/client/ui/button/ButtonConnector.java
@@ -156,7 +156,13 @@ public class ButtonConnector extends AbstractComponentConnector implements
@Override
public void onClick(ClickEvent event) {
if (getState().disableOnClick) {
- getWidget().setEnabled(false);
+ // Simulate getting disabled from the server without waiting for the
+ // round trip. The server-side RPC handler takes care of updating
+ // the server-side state in a similar way to ensure subsequent
+ // changes are properly propagated. Changing state on client is not
+ // generally supported.
+ getState().enabled = false;
+ super.updateEnabledState(false);
rpc.disableOnClick();
}
diff --git a/server/src/com/vaadin/ui/Button.java b/server/src/com/vaadin/ui/Button.java
index d248efd570..b4b7bf64be 100644
--- a/server/src/com/vaadin/ui/Button.java
+++ b/server/src/com/vaadin/ui/Button.java
@@ -19,6 +19,8 @@ package com.vaadin.ui;
import java.io.Serializable;
import java.lang.reflect.Method;
+import org.json.JSONException;
+
import com.vaadin.event.Action;
import com.vaadin.event.FieldEvents;
import com.vaadin.event.FieldEvents.BlurEvent;
@@ -55,10 +57,17 @@ public class Button extends AbstractComponent implements
}
@Override
- public void disableOnClick() {
- // Could be optimized so the button is not repainted because of
- // this (client side has already disabled the button)
+ public void disableOnClick() throws RuntimeException {
setEnabled(false);
+ // Makes sure the enabled=false state is noticed at once - otherwise
+ // a following setEnabled(true) call might have no effect. see
+ // ticket #10030
+ try {
+ getUI().getConnectorTracker().getDiffState(Button.this)
+ .put("enabled", false);
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
}
};
diff --git a/uitest/src/com/vaadin/tests/components/button/ButtonDisableEnableOnClick.html b/uitest/src/com/vaadin/tests/components/button/ButtonDisableEnableOnClick.html
new file mode 100644
index 0000000000..a3cdb64aec
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/button/ButtonDisableEnableOnClick.html
@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8888/" />
+<title>ButtonDisableEnableOnClick</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">ButtonDisableEnableOnClick</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.button.Buttons3?restartApplication</td>
+ <td></td>
+</tr>
+<!--setDisableOnClick(true)-->
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::PID_Smenu#item0</td>
+ <td>17,12</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::Root/VOverlay[0]/VMenuBar[0]#item4</td>
+ <td>19,10</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::Root/VOverlay[1]/VMenuBar[0]#item0</td>
+ <td>24,8</td>
+</tr>
+<!--addClickListener where onClick() { button.setEnabled(true) }-->
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::PID_Smenu#item0</td>
+ <td>38,8</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::Root/VOverlay[0]/VMenuBar[0]#item3</td>
+ <td>18,10</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::Root/VOverlay[1]/VMenuBar[0]#item2</td>
+ <td>37,11</td>
+</tr>
+<!--click should not disable button-->
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::PID_StestComponent/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>id=Log_row_0</td>
+ <td>2. ClickEvent</td>
+</tr>
+<tr>
+ <td>assertNotCSSClass</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::PID_StestComponent</td>
+ <td>v-disabled</td>
+</tr>
+<!--another click should not disable button-->
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::PID_StestComponent/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>id=Log_row_0</td>
+ <td>3. ClickEvent</td>
+</tr>
+<tr>
+ <td>assertNotCSSClass</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::PID_StestComponent</td>
+ <td>v-disabled</td>
+</tr>
+<!--another click should not disable button-->
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::PID_StestComponent/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>id=Log_row_0</td>
+ <td>4. ClickEvent</td>
+</tr>
+<tr>
+ <td>assertNotCSSClass</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::PID_StestComponent</td>
+ <td>v-disabled</td>
+</tr>
+<!--remove clickListener-->
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::PID_Smenu#item0</td>
+ <td>29,7</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::Root/VOverlay[0]/VMenuBar[0]#item3</td>
+ <td>20,8</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::Root/VOverlay[1]/VMenuBar[0]#item2</td>
+ <td>26,6</td>
+</tr>
+<!--click should now disable the button-->
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::PID_StestComponent/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertCSSClass</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons3::PID_StestComponent</td>
+ <td>v-disabled</td>
+</tr>
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/button/Buttons3.java b/uitest/src/com/vaadin/tests/components/button/Buttons3.java
new file mode 100644
index 0000000000..b20effad97
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/button/Buttons3.java
@@ -0,0 +1,16 @@
+package com.vaadin.tests.components.button;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+
+public class Buttons3<T extends Button> extends Buttons2<T> implements
+ ClickListener {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ event.getButton().setEnabled(true);
+ super.buttonClick(event);
+ }
+
+}