aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur.signell@itmill.com>2008-11-24 14:50:32 +0000
committerArtur Signell <artur.signell@itmill.com>2008-11-24 14:50:32 +0000
commit5cf770c597a22c97517fb25486de04d50d296e38 (patch)
tree858ccbc1293a56fc4b726b8361376f1f12f94a2c
parent8665aac686c47c11c7e056245098adc6b6fa8e01 (diff)
downloadvaadin-framework-5cf770c597a22c97517fb25486de04d50d296e38.tar.gz
vaadin-framework-5cf770c597a22c97517fb25486de04d50d296e38.zip
Test case and fix for #2151 - Button should not accept invalid values.
svn changeset:5966/svn branch:trunk
-rw-r--r--src/com/itmill/toolkit/tests/tickets/Ticket2151.java108
-rw-r--r--src/com/itmill/toolkit/ui/Button.java17
2 files changed, 121 insertions, 4 deletions
diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket2151.java b/src/com/itmill/toolkit/tests/tickets/Ticket2151.java
new file mode 100644
index 0000000000..52fbe2a9de
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/tickets/Ticket2151.java
@@ -0,0 +1,108 @@
+package com.itmill.toolkit.tests.tickets;
+
+import com.itmill.toolkit.Application;
+import com.itmill.toolkit.data.util.ObjectProperty;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.CheckBox;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.Window;
+
+public class Ticket2151 extends Application {
+
+ private Label status;
+
+ public void init() {
+ Window w = new Window(getClass().getSimpleName());
+ setMainWindow(w);
+ // setTheme("tests-tickets");
+ createUI((OrderedLayout) w.getLayout());
+ }
+
+ private void createUI(OrderedLayout layout) {
+ Button b = new Button("This is a button");
+ CheckBox cb = new CheckBox("This is a checkbox");
+ cb.setImmediate(true);
+ setTheme("tests-tickets");
+ layout.setStyleName("mylayout");
+ status = new Label("Result:");
+ layout.addComponent(status);
+ layout.setSpacing(true);
+ layout.setMargin(true);
+
+ layout.addComponent(b);
+ layout.addComponent(cb);
+
+ layout.addComponent(new Label("a"));
+ layout.addComponent(new Label("b"));
+ layout.addComponent(new Label("c"));
+
+ check(Button.class);
+ check(CheckBox.class);
+ checkDataBinding(Button.class);
+ checkDataBinding(CheckBox.class);
+
+ }
+
+ private void check(Class<? extends Button> class1) {
+ boolean ok = false;
+ Button b;
+ try {
+ b = class1.newInstance();
+ b.setCaption("Button of type " + class1.getSimpleName());
+ try {
+ // This should throw an exception
+ b.setValue("ON");
+ } catch (IllegalArgumentException e) {
+ ok = true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ return;
+ }
+
+ if (ok) {
+ status.setValue(status.getValue() + " "
+ + class1.getClass().getSimpleName() + ": OK");
+ } else {
+ status.setValue(status.getValue() + " "
+ + class1.getClass().getSimpleName() + ": FAILED");
+ }
+
+ }
+
+ private void checkDataBinding(Class<? extends Button> class1) {
+ boolean ok = false;
+ Button b;
+ try {
+ b = class1.newInstance();
+ b.setCaption("Button of type " + class1.getSimpleName());
+ try {
+ b.setWriteThrough(true);
+ b.setReadThrough(true);
+ ObjectProperty prop = new ObjectProperty("ABC 123");
+ /*
+ * This should throw an exception or somehow tell that the
+ * property was invalid (wrong type). See #2223.
+ */
+ b.setPropertyDataSource(prop);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ return;
+ }
+
+ if (ok) {
+ status.setValue(status.getValue() + " "
+ + class1.getClass().getSimpleName() + "/DB: OK");
+ } else {
+ status.setValue(status.getValue() + " "
+ + class1.getClass().getSimpleName() + "/DB: FAILED");
+ }
+
+ }
+}
diff --git a/src/com/itmill/toolkit/ui/Button.java b/src/com/itmill/toolkit/ui/Button.java
index 0812f261ff..2bd0aac48d 100644
--- a/src/com/itmill/toolkit/ui/Button.java
+++ b/src/com/itmill/toolkit/ui/Button.java
@@ -27,8 +27,8 @@ public class Button extends AbstractField {
boolean switchMode = false;
/**
- * Creates a new push button. The value of the push button is allways false
- * and they are immediate by default.
+ * Creates a new push button. The value of the push button is false and it
+ * is immediate by default.
*
*/
public Button() {
@@ -39,8 +39,7 @@ public class Button extends AbstractField {
/**
* Creates a new push button.
*
- * The value of the push button is allways false and they are immediate by
- * default.
+ * The value of the push button is false and it is immediate by default.
*
* @param caption
* the Button caption.
@@ -336,4 +335,14 @@ public class Button extends AbstractField {
fireEvent(new Button.ClickEvent(this));
}
+ @Override
+ protected void setInternalValue(Object newValue) {
+ // Make sure only booleans get through
+ if (!(newValue instanceof Boolean)) {
+ throw new IllegalArgumentException(getClass().getSimpleName()
+ + " only accepts Boolean values");
+ }
+ super.setInternalValue(newValue);
+ }
+
}