Revision: 8739
Author: cromwell...@google.com
Date: Thu Sep 9 10:59:13 2010
Log: Allow Checkbox to accept null as valid.
Review at http://gwt-code-reviews.appspot.com/831803
Review by: rj...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=8739
Modified:
/trunk/user/src/com/google/gwt/user/client/ui/CheckBox.java
/trunk/user/src/com/google/gwt/user/client/ui/HasValue.java
/trunk/user/test/com/google/gwt/user/client/ui/CheckBoxTest.java
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/CheckBox.java Tue Apr 20
03:28:08 2010
+++ /trunk/user/src/com/google/gwt/user/client/ui/CheckBox.java Thu Sep 9
10:59:13 2010
@@ -289,14 +289,14 @@
* input element wrapped by this widget. For access to that property, see
* {...@link #setFormValue(String)}
*
- * @param value true to check, false to uncheck; must not be null
+ * @param value true to check, false to uncheck; null value implies false
* @param fireEvents If true, and value has changed, fire a
* {...@link ValueChangeEvent}
* @throws IllegalArgumentException if value is null
*/
public void setValue(Boolean value, boolean fireEvents) {
if (value == null) {
- throw new IllegalArgumentException("value must not be null");
+ value = Boolean.FALSE;
}
Boolean oldValue = getValue();
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/HasValue.java Wed Sep 1
14:06:53 2010
+++ /trunk/user/src/com/google/gwt/user/client/ui/HasValue.java Thu Sep 9
10:59:13 2010
@@ -46,9 +46,10 @@
* It is acceptable to fail assertions or throw (documented) unchecked
* exceptions in response to bad values.
* <p>
- * By convention, GWT widgets that can be cleared accept null for
- * <code>value</code>, but it is acceptable for widgets that cannot be
cleared
- * to throw an exception for null values.
+ * Widgets must accept null as a valid value. By convention, setting a
widget to
+ * null clears value, calling getValue() on a cleared widget returns
null. Widgets
+ * that can not be cleared (e.g. {...@link CheckBox}) must find another
valid meaning
+ * for null input.
*
* @param value the object's new value
*/
=======================================
--- /trunk/user/test/com/google/gwt/user/client/ui/CheckBoxTest.java Tue
Apr 20 03:28:08 2010
+++ /trunk/user/test/com/google/gwt/user/client/ui/CheckBoxTest.java Thu
Sep 9 10:59:13 2010
@@ -82,6 +82,10 @@
cb.setValue(false);
assertFalse(cb.getValue());
+ // null implies false
+ cb.setValue(null);
+ assertFalse(cb.getValue());
+
cb.setEnabled(false);
assertFalse(cb.isEnabled());
cb.setEnabled(true);
@@ -239,13 +243,6 @@
cb.setValue(true, true);
assertTrue(h.received);
-
- try {
- cb.setValue(null);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- /* pass */
- }
// Note that we cannot test this with a simulated click, the way
// we do for the click handlers. IE does not change the value of
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors