Fixes a bug where checkboxes would not retain their value on IE when detached.  We were accidentally short-circuiting the logic that would set the default checked property during widget unload.

Review by: rjrjr (desk)


git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/1.6@4611 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/CheckBox.java b/user/src/com/google/gwt/user/client/ui/CheckBox.java
index 7aad9ba..40386ff 100644
--- a/user/src/com/google/gwt/user/client/ui/CheckBox.java
+++ b/user/src/com/google/gwt/user/client/ui/CheckBox.java
@@ -303,11 +303,12 @@
       throw new IllegalArgumentException("value must not be null");
     }
 
-    if (value.equals(getValue())) {
-      return;
-    }
+    Boolean oldValue = getValue();
     inputElem.setChecked(value);
     inputElem.setDefaultChecked(value);
+    if (value.equals(oldValue)) {
+      return;
+    }
     if (fireEvents) {
       ValueChangeEvent.fire(this, value);
     }
diff --git a/user/test/com/google/gwt/user/client/ui/CheckBoxTest.java b/user/test/com/google/gwt/user/client/ui/CheckBoxTest.java
index 3f9a6f9..2a4ed97 100644
--- a/user/test/com/google/gwt/user/client/ui/CheckBoxTest.java
+++ b/user/test/com/google/gwt/user/client/ui/CheckBoxTest.java
@@ -119,6 +119,20 @@
     UIObjectTest.assertDebugIdContents("myCheck-label", "myLabel");
   }
 
+  /**
+   * Tests that detaching and attaching a CheckBox widget retains the checked
+   * state of the element. This is known to be tricky on IE.
+   */
+  public void testDetachment() {
+    InputElement elm = DOM.createInputCheck().cast();
+    CheckBox box = new CheckBox(elm.<Element> cast());
+    RootPanel.get().add(box);
+    elm.setChecked(true);
+    RootPanel.get().remove(box);
+    RootPanel.get().add(box);
+    assertTrue(elm.isChecked());
+  }
+
   public void testFormValue() {
     InputElement elm = Document.get().createCheckInputElement();
     Element asOldElement = elm.cast();