Author: jdonnerstag
Date: Thu Feb 11 18:14:57 2010
New Revision: 909099
URL: http://svn.apache.org/viewvc?rev=909099&view=rev
Log:
fixed: Form#anyComponentError change in 1.4 breaks validation. Couldn't really
test it since 1.5 doesn't yet compile.
Issue: WICKET-2374
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage$InvalidPanel.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/TestFormHasError.java
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java?rev=909099&r1=909098&r2=909099&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
Thu Feb 11 18:14:57 2010
@@ -1025,36 +1025,22 @@
*/
private boolean anyFormComponentError()
{
- final boolean[] error = new boolean[] { false };
-
- final IVisitor<Component> visitor = new IVisitor<Component>()
+ // Check ALL children for error messages irrespective of
FormComponents or not
+ Boolean error = (Boolean)visitChildren(Component.class, new
IVisitor<Component>()
{
public Object component(final Component component)
{
if (component.hasErrorMessage())
{
- error[0] = true;
- return
Component.IVisitor.STOP_TRAVERSAL;
+ return Boolean.TRUE;
}
// Traverse all children
return Component.IVisitor.CONTINUE_TRAVERSAL;
}
- };
-
- visitChildren(Component.class, new IVisitor<Component>()
- {
- public Object component(final Component component)
- {
- if ((component instanceof Form) || (component
instanceof FormComponent))
- {
- return visitor.component(component);
- }
- return Component.IVisitor.CONTINUE_TRAVERSAL;
- }
});
- return error[0];
+ return (error != null) && error;
}
/**
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage$InvalidPanel.html
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage%24InvalidPanel.html?rev=909099&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage$InvalidPanel.html
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage$InvalidPanel.html
Thu Feb 11 18:14:57 2010
@@ -0,0 +1,16 @@
+<html
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" >
+ <head>
+ <title>Wicket Quickstart Archetype Homepage</title>
+ </head>
+ <body>
+ <strong>anyComponentError test</strong>
+ <br/><br/>
+ <span wicket:id="passFail"></span>
+ <form id="form">
+ <wicket:panel>
+ When the form is submitted, this panel will have a
validation error;
+ it should cause the form submission to fail.
+ </wicket:panel>
+ </form>
+ </body>
+</html>
\ No newline at end of file
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage.html
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage.html?rev=909099&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage.html
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage.html
Thu Feb 11 18:14:57 2010
@@ -0,0 +1,21 @@
+<html
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" >
+ <head>
+ <title>Wicket Quickstart Archetype Homepage</title>
+ </head>
+ <body>
+ <strong>anyComponentError test</strong>
+ <br/><br/>
+ <b><span wicket:id="passFail"></span></b>
+ <form wicket:id="form">
+ <div wicket:id="invalidPanel">[invalidPanel]</div>
+ <input wicket:id="submitComponent" type="button" value="Click
to test Panel" />
+ <div>
+ <input wicket:id="formComponent" type="checkbox" />
+ </div>
+ <input wicket:id="submitFormComponent" type="button"
value="Click to test FormComponent" />
+ <br />
+ <input wicket:id="submitForm" type="button" value="Click to
test Form" />
+ </form>
+ <div wicket:id="feedback">[feedback]</div>
+ </body>
+</html>
\ No newline at end of file
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage.java?rev=909099&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage.java
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormHasErrorPage.java
Thu Feb 11 18:14:57 2010
@@ -0,0 +1,111 @@
+/*
+ * 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.markup.html.form;
+
+import junit.framework.Assert;
+
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.panel.FeedbackPanel;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+
+/**
+ * FormHasErrorPage
+ */
+public class FormHasErrorPage extends WebPage
+{
+ public static final class InvalidPanel extends Panel
+ {
+ public InvalidPanel(String id)
+ {
+ super(id);
+ }
+ }
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor that is invoked when page is invoked without a session.
+ *
+ * @param parameters
+ * Page parameters
+ */
+ public FormHasErrorPage(final PageParameters parameters)
+ {
+
+ final IModel<String> labelModel = new Model<String>("");
+ Label passFail = new Label("passFail", labelModel);
+ add(passFail);
+
+ final SubmitLink submitComponent = new
SubmitLink("submitComponent");
+ final SubmitLink submitFormComponent = new
SubmitLink("submitFormComponent");
+ final SubmitLink submitForm = new SubmitLink("submitForm");
+
+ final InvalidPanel invalidPanel = new
InvalidPanel("invalidPanel");
+ final CheckBox formComponent = new CheckBox("formComponent",
new Model());
+
+ Form form = new Form("form")
+ {
+ @Override
+ protected void onError()
+ {
+ super.onError();
+ labelModel.setObject("Test PASSED - an error
was expected.");
+ }
+
+ @Override
+ protected void onSubmit()
+ {
+ super.onSubmit();
+ labelModel.setObject("Test FAILED - an error
was expected");
+ Assert.fail("A validation error should've been
detected by the Form processing");
+ }
+
+ @Override
+ public void process(IFormSubmittingComponent
submittingComponent)
+ {
+ // set the error based on which link submitted
the form
+ if (submittingComponent == submitFormComponent)
+ {
+ formComponent.error("FormComponent
validation error");
+ }
+ else if (submittingComponent == submitComponent)
+ {
+ invalidPanel.error("Panel validation
error");
+ }
+ else
+ {
+ error("Form validation error");
+ }
+
+ super.process(submittingComponent);
+ }
+ };
+ add(form);
+ form.add(submitComponent);
+ form.add(submitFormComponent);
+ form.add(submitForm);
+
+ form.add(invalidPanel);
+ form.add(formComponent);
+
+ add(new FeedbackPanel("feedback"));
+ }
+}
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/TestFormHasError.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/TestFormHasError.java?rev=909099&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/TestFormHasError.java
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/TestFormHasError.java
Thu Feb 11 18:14:57 2010
@@ -0,0 +1,64 @@
+/*
+ * 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.markup.html.form;
+
+import junit.framework.TestCase;
+
+import org.apache.wicket.ng.mock.WicketTester;
+
+public class TestFormHasError extends TestCase
+{
+ private WicketTester tester;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ tester = new WicketTester();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ tester = null;
+ }
+
+ public void testFormHasError()
+ {
+ tester.startPage(FormHasErrorPage.class);
+ tester.assertRenderedPage(FormHasErrorPage.class);
+ tester.clickLink("form:submitForm");
+ tester.dumpPage();
+ }
+
+ public void testFormComponentHasError()
+ {
+ tester.startPage(FormHasErrorPage.class);
+ tester.assertRenderedPage(FormHasErrorPage.class);
+ tester.clickLink("form:submitFormComponent");
+ tester.dumpPage();
+ }
+
+ public void testComponentHasError()
+ {
+ tester.startPage(FormHasErrorPage.class);
+ tester.assertRenderedPage(FormHasErrorPage.class);
+ tester.clickLink("form:submitComponent");
+ tester.dumpPage();
+ }
+}