Author: jdonnerstag
Date: Sat Jan 17 05:37:54 2009
New Revision: 735288
URL: http://svn.apache.org/viewvc?rev=735288&view=rev
Log:
fixed wicket-2025: Forms are not validated correctly inside a border
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/HomePage.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/HomePage.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/MyBorder.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/MyBorder.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/TestHomePage.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=735288&r1=735287&r2=735288&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
Sat Jan 17 05:37:54 2009
@@ -1194,21 +1194,38 @@
*/
private boolean anyFormComponentError()
{
- final Object value = visitChildren(new IVisitor<Component>()
+ final boolean[] error = new boolean[] { false };
+
+ final FormComponent.IVisitor visitor = new
FormComponent.IVisitor()
{
- public Object component(final Component component)
+ public Object formComponent(IFormVisitorParticipant
formComponent)
{
- if (component.hasErrorMessage())
+ if (formComponent instanceof Component &&
+
((Component)formComponent).hasErrorMessage())
{
- return STOP_TRAVERSAL;
+ error[0] = true;
+ return
Component.IVisitor.STOP_TRAVERSAL;
}
// Traverse all children
- return CONTINUE_TRAVERSAL;
+ return Component.IVisitor.CONTINUE_TRAVERSAL;
+ }
+ };
+
+ visitChildren(FormComponent.class, new IVisitor<Component>()
+ {
+ public Object component(final Component component)
+ {
+ return
visitor.formComponent((FormComponent<?>)component);
}
});
- return value == IVisitor.STOP_TRAVERSAL ? true : false;
+ if (!error[0])
+ {
+ visitChildrenInContainingBorder(visitor);
+ }
+
+ return error[0];
}
/**
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/HomePage.html
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/HomePage.html?rev=735288&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/HomePage.html
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/HomePage.html
Sat Jan 17 05:37:54 2009
@@ -0,0 +1,22 @@
+<html>
+ <head>
+ <title>Wicket Quickstart Archetype Homepage</title>
+ </head>
+ <body>
+ <strong>Wicket Quickstart Archetype Homepage</strong>
+ <br/><br/>
+ <span wicket:id="message">message will be here</span>
+
+ <form wicket:id="form">
+ <div wicket:id="feedback" />
+ <input wicket:id="textfield1" /> - <span
wicket:id="lbltextfield1" /><br />
+ <input wicket:id="textfield2" /> - <span
wicket:id="lbltextfield2" /><br />
+ <button wicket:id="submit" type="submit">submit</button>
+ </form>
+
+ <div wicket:id="border">
+ <input wicket:id="textfield1" /> - <span
wicket:id="lbltextfield1" /><br />
+ <input wicket:id="textfield2" /> - <span
wicket:id="lbltextfield2" /><br />
+ </div>
+ </body>
+</html>
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/HomePage.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/HomePage.java?rev=735288&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/HomePage.java
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/HomePage.java
Sat Jan 17 05:37:54 2009
@@ -0,0 +1,101 @@
+/*
+ * 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.validation;
+
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.html.panel.FeedbackPanel;
+import org.apache.wicket.model.PropertyModel;
+
+/**
+ * Homepage
+ */
+public class HomePage extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+
+ /** */
+ public String textfieldForm1, textfieldForm2;
+
+ /** */
+ public String textfield1, textfield2;
+
+ /**
+ * Constructor that is invoked when page is invoked without a session.
+ *
+ * @param parameters
+ * Page parameters
+ */
+ public HomePage(final PageParameters parameters)
+ {
+
+ // Add the simplest type of label
+ add(new Label("message",
+ "If you see this message wicket is properly configured
and running"));
+
+ final Form<Void> form = new Form<Void>("form");
+ form.setOutputMarkupId(true);
+ add(form);
+
+ form.add(new FeedbackPanel("feedback"));
+
+ form.add(new TextField<String>("textfield1", new
PropertyModel<String>(this,
+ "textfieldForm1")).setRequired(true));
+ form.add(new Label("lbltextfield1", new
PropertyModel<String>(this, "textfieldForm1")));
+
+ form.add(new TextField<String>("textfield2", new
PropertyModel<String>(this,
+ "textfieldForm2")));
+ form.add(new Label("lbltextfield2", new
PropertyModel<String>(this, "textfieldForm2")));
+
+ form.add(new AjaxSubmitLink("submit")
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void onSubmit(AjaxRequestTarget target,
Form<?> form)
+ {
+ info("onSubmit");
+ target.addComponent(form);
+ }
+
+ @Override
+ protected void onError(AjaxRequestTarget target,
Form<?> form)
+ {
+ error("onError");
+ target.addComponent(form);
+ }
+ });
+
+ // --------------------
+
+ MyBorder border = new MyBorder("border");
+ add(border);
+
+ border.add(new TextField<String>("textfield1",
+ new PropertyModel<String>(this,
"textfield1")).setRequired(true));
+ border.add(new Label("lbltextfield1", new
PropertyModel<String>(this, "textfield1")));
+
+ border.add(new TextField<String>("textfield2",
+ new PropertyModel<String>(this, "textfield2")));
+ border.add(new Label("lbltextfield2", new
PropertyModel<String>(this, "textfield2")));
+ }
+}
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/MyBorder.html
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/MyBorder.html?rev=735288&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/MyBorder.html
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/MyBorder.html
Sat Jan 17 05:37:54 2009
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:wicket="http://wicket.apache.org/"
+>
+<head>
+</head>
+<body>
+<wicket:border>
+
+<form wicket:id="form2">
+ <div wicket:id="feedback" />
+ <wicket:body />
+ <button wicket:id="submit" type="submit">submit</button>
+</form>
+
+</wicket:border>
+</body>
+</html>
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/MyBorder.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/MyBorder.java?rev=735288&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/MyBorder.java
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/MyBorder.java
Sat Jan 17 05:37:54 2009
@@ -0,0 +1,74 @@
+/*
+ * 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.validation;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
+import org.apache.wicket.markup.html.border.Border;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.panel.FeedbackPanel;
+
+/**
+ *
+ */
+public class MyBorder extends Border
+{
+ private static final long serialVersionUID = 1L;
+ Form<Void> form;
+
+ /**
+ * Construct.
+ *
+ * @param id
+ */
+ public MyBorder(String id)
+ {
+ super(id);
+
+ form = new Form<Void>("form2");
+ form.setOutputMarkupId(true);
+ add(form);
+
+ form.add(new FeedbackPanel("feedback"));
+
+ form.add(new AjaxSubmitLink("submit")
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void onSubmit(AjaxRequestTarget target,
Form<?> form)
+ {
+ info("onSubmit");
+ target.addComponent(form);
+ }
+
+ @Override
+ protected void onError(AjaxRequestTarget target,
Form<?> form)
+ {
+ error("onError");
+ target.addComponent(form);
+ }
+ });
+ }
+
+ @Override
+ protected void onBeforeRender()
+ {
+ super.onBeforeRender();
+ form.add(getBodyContainer());
+ }
+}
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/TestHomePage.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/TestHomePage.java?rev=735288&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/TestHomePage.java
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/validation/TestHomePage.java
Sat Jan 17 05:37:54 2009
@@ -0,0 +1,91 @@
+/*
+ * 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.validation;
+
+import junit.framework.TestCase;
+
+import org.apache.wicket.feedback.FeedbackMessage;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.util.tester.FormTester;
+import org.apache.wicket.util.tester.WicketTester;
+
+/**
+ * Simple test using the WicketTester
+ */
+public class TestHomePage extends TestCase
+{
+ private WicketTester tester;
+
+ private FormTester formTester;
+
+ @Override
+ public void setUp()
+ {
+ tester = new WicketTester();
+
+ // Start and render the test page
+ tester.startPage(HomePage.class);
+ tester.assertRenderedPage(HomePage.class);
+ }
+
+ /**
+ *
+ */
+ public void testWithoutBorder()
+ {
+ formTester = tester.newFormTester("form");
+ formTester.submit();
+ assertEquals("Expected one error message",
+ tester.getMessages(FeedbackMessage.ERROR).size(), 1);
+ }
+
+ /**
+ *
+ */
+ public void testWithoutBorder2()
+ {
+ formTester = tester.newFormTester("form");
+ formTester.setValue("textfield1", "testxxx");
+ formTester.submit();
+ tester.assertNoErrorMessage();
+ }
+
+ /**
+ *
+ */
+ public void testWithBorder()
+ {
+ formTester = tester.newFormTester("border:form2");
+ formTester.submit();
+ assertEquals("Expected one error message",
+ tester.getMessages(FeedbackMessage.ERROR).size(), 1);
+ }
+
+ /**
+ *
+ */
+ public void testWithBorder2()
+ {
+ formTester = tester.newFormTester("border:form2");
+ // formTester.setValue("..:textfield1", "testxxx");
+ TextField<String> textfield =
(TextField<String>)tester.getLastRenderedPage().get(
+ "border:textfield1");
+
tester.getServletRequest().setParameter(textfield.getInputName(), "abcde");
+ formTester.submit();
+ tester.assertNoErrorMessage();
+ }
+}