Updated Branches:
  refs/heads/wicket-6.x c99451440 -> f81b6e350

WICKET-5230 use #isValid() instead of #hasErrorMessage() as the FormComponent 
does too


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/f81b6e35
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/f81b6e35
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/f81b6e35

Branch: refs/heads/wicket-6.x
Commit: f81b6e350952e1ea5ce1823daa96f02a6fa6b327
Parents: c994514
Author: svenmeier <s...@meiers.net>
Authored: Wed Jun 12 20:46:01 2013 +0200
Committer: svenmeier <s...@meiers.net>
Committed: Wed Jun 12 20:49:08 2013 +0200

----------------------------------------------------------------------
 .../form/AjaxFormComponentUpdatingBehavior.java | 14 ++--
 ...FormChoiceComponentUpdatingBehaviorTest.java | 45 +++++++++++++
 .../wicket/ajax/form/ChoiceComponentPage.html   | 16 +++++
 .../wicket/ajax/form/ChoiceComponentPage.java   | 70 ++++++++++++++++++++
 4 files changed, 138 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/f81b6e35/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.java
 
b/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.java
index e78c67d..7eab478 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.java
@@ -140,13 +140,7 @@ public abstract class AjaxFormComponentUpdatingBehavior 
extends AjaxEventBehavio
                {
                        formComponent.inputChanged();
                        formComponent.validate();
-                       if (formComponent.hasErrorMessage())
-                       {
-                               formComponent.invalid();
-
-                               onError(target, null);
-                       }
-                       else
+                       if (formComponent.isValid())
                        {
                                formComponent.valid();
                                if (getUpdateModel())
@@ -156,6 +150,12 @@ public abstract class AjaxFormComponentUpdatingBehavior 
extends AjaxEventBehavio
 
                                onUpdate(target);
                        }
+                       else
+                       {
+                               formComponent.invalid();
+
+                               onError(target, null);
+                       }
                }
                catch (RuntimeException e)
                {

http://git-wip-us.apache.org/repos/asf/wicket/blob/f81b6e35/wicket-core/src/test/java/org/apache/wicket/ajax/form/AjaxFormChoiceComponentUpdatingBehaviorTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/ajax/form/AjaxFormChoiceComponentUpdatingBehaviorTest.java
 
b/wicket-core/src/test/java/org/apache/wicket/ajax/form/AjaxFormChoiceComponentUpdatingBehaviorTest.java
new file mode 100644
index 0000000..348b291
--- /dev/null
+++ 
b/wicket-core/src/test/java/org/apache/wicket/ajax/form/AjaxFormChoiceComponentUpdatingBehaviorTest.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.ajax.form;
+
+import org.apache.wicket.WicketTestCase;
+import org.junit.Test;
+
+public class AjaxFormChoiceComponentUpdatingBehaviorTest extends WicketTestCase
+{
+
+       /**
+        * WICKET-5230 nested FormComponent with error message makes group 
invalid
+        */
+       @Test
+       public void nestedInvalidFormComponent()
+       {
+               ChoiceComponentPage page = 
tester.startPage(ChoiceComponentPage.class);
+
+               tester.submitForm(page.form);
+
+               assertTrue(page.text.hasErrorMessage());
+
+               tester.getRequest().setParameter("form.group", 
page.radioFalse.getValue());
+               tester.executeAjaxEvent(page.group, "click");
+
+               // group is invalid because nested text has error message
+               assertFalse(page.group.isValid());
+               // .. so model object stays unchanged
+               assertEquals(Boolean.TRUE, page.group.getModelObject());
+       }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f81b6e35/wicket-core/src/test/java/org/apache/wicket/ajax/form/ChoiceComponentPage.html
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/ajax/form/ChoiceComponentPage.html
 
b/wicket-core/src/test/java/org/apache/wicket/ajax/form/ChoiceComponentPage.html
new file mode 100644
index 0000000..15fcfaa
--- /dev/null
+++ 
b/wicket-core/src/test/java/org/apache/wicket/ajax/form/ChoiceComponentPage.html
@@ -0,0 +1,16 @@
+<html>
+    <head>
+    </head>
+    <body>
+        <form wicket:id="form">
+          <div wicket:id="group">
+               <input type="radio" wicket:id="radioTrue" />
+               <input type="radio" wicket:id="radioFalse" />
+               
+               <input type="text" wicket:id="text" />
+          </div>
+        </form>
+        
+    </body>
+</html>
+

http://git-wip-us.apache.org/repos/asf/wicket/blob/f81b6e35/wicket-core/src/test/java/org/apache/wicket/ajax/form/ChoiceComponentPage.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/ajax/form/ChoiceComponentPage.java
 
b/wicket-core/src/test/java/org/apache/wicket/ajax/form/ChoiceComponentPage.java
new file mode 100644
index 0000000..c1dd6c6
--- /dev/null
+++ 
b/wicket-core/src/test/java/org/apache/wicket/ajax/form/ChoiceComponentPage.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.ajax.form;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.Radio;
+import org.apache.wicket.markup.html.form.RadioGroup;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.Model;
+
+/**
+ * Page hosting a choice component.
+ */
+public class ChoiceComponentPage extends WebPage
+{
+       private static final long serialVersionUID = 1L;
+
+       public final Form<Void> form;
+
+       public final TextField<String> text;
+
+       public final RadioGroup<Boolean> group;
+
+       public final Radio<Boolean> radioTrue;
+
+       public final Radio<Boolean> radioFalse;
+
+       /**
+        */
+       public ChoiceComponentPage()
+       {
+               form = new Form<Void>("form");
+               add(form);
+
+               group = new RadioGroup<Boolean>("group", new 
Model(Boolean.TRUE));
+               group.add(new AjaxFormChoiceComponentUpdatingBehavior()
+               {
+                       @Override
+                       protected void onUpdate(AjaxRequestTarget target)
+                       {
+                       }
+               });
+               form.add(group);
+
+               radioTrue = new Radio<Boolean>("radioTrue", 
Model.of(Boolean.TRUE));
+               group.add(radioTrue);
+
+               radioFalse = new Radio<Boolean>("radioFalse", 
Model.of(Boolean.FALSE));
+               group.add(radioFalse);
+
+               text = new TextField<String>("text", Model.of(""));
+               group.add(text.setRequired(true));
+       }
+}

Reply via email to