WICKET-6462 added regression test Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/08be805e Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/08be805e Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/08be805e
Branch: refs/heads/wicket-7.x Commit: 08be805e120a08e5acd659b8c94f10702cbc5c49 Parents: bedf3fd Author: Andrea Del Bene <adelb...@apache.org> Authored: Tue Sep 5 12:53:08 2017 +0200 Committer: Andrea Del Bene <andrea.delb...@innoteam.it> Committed: Tue Sep 5 17:54:08 2017 +0200 ---------------------------------------------------------------------- .../ajax/form/AjaxFormSubmitBehaviorTest.java | 44 +++++++++----- .../org/apache/wicket/ajax/form/PanelEdit.html | 47 +++++++++++++++ .../org/apache/wicket/ajax/form/PanelEdit.java | 60 ++++++++++++++++++++ 3 files changed, 136 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/08be805e/wicket-core/src/test/java/org/apache/wicket/ajax/form/AjaxFormSubmitBehaviorTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/form/AjaxFormSubmitBehaviorTest.java b/wicket-core/src/test/java/org/apache/wicket/ajax/form/AjaxFormSubmitBehaviorTest.java index 48f55a9..a0cab5d 100644 --- a/wicket-core/src/test/java/org/apache/wicket/ajax/form/AjaxFormSubmitBehaviorTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/ajax/form/AjaxFormSubmitBehaviorTest.java @@ -16,6 +16,8 @@ */ package org.apache.wicket.ajax.form; +import org.apache.wicket.Component; +import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.form.AjaxButton; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.util.tester.FormTester; @@ -53,43 +55,55 @@ public class AjaxFormSubmitBehaviorTest extends WicketTestCase tester.startPage(NestedFormTestPage.class); NestedFormTestPage homePage = (NestedFormTestPage)tester.getLastRenderedPage(); - assertFalse(homePage.innerFormSubmitted); + assertFalse(homePage.innerSubmitted); FormTester formTester = tester.newFormTester("outer:inner"); formTester.submit("submit"); - assertTrue(homePage.innerFormSubmitted); + assertTrue(homePage.innerSubmitted); } + /** + * https://issues.apache.org/jira/browse/WICKET-6462 + * + * onSubmit must be called once. + */ + @Test + public void formReplacement() + { + PanelEdit panelEdit = tester.startComponentInPage(PanelEdit.class); + FormTester formTester = tester.newFormTester(panelEdit.getId() + ":form"); + //AjaxFormSubmitBehavior onSubmit must not be called when form is removed + formTester.submit("submit"); + } + public static class NestedFormTestPage extends NestedFormPage { - public boolean innerFormSubmitted = false; + /** + * + */ + private static final long serialVersionUID = -515262294201762225L; + public NestedFormTestPage() { - Form<?> outer = new Form("outer"); - replace(outer); - - Form<?> inner = new Form("inner") - { + Form<?> inner = new Form("inner") { @Override - protected boolean wantSubmitOnParentFormSubmit() - { + protected boolean wantSubmitOnParentFormSubmit() { return false; } @Override - protected void onSubmit() - { + protected void onSubmit() { super.onSubmit(); - innerFormSubmitted = true; + innerSubmitted = true; } }; - outer.add(inner); - inner.add(new AjaxButton("submit", inner) {}); + + get("outer:inner").replaceWith(inner); } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/wicket/blob/08be805e/wicket-core/src/test/java/org/apache/wicket/ajax/form/PanelEdit.html ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/form/PanelEdit.html b/wicket-core/src/test/java/org/apache/wicket/ajax/form/PanelEdit.html new file mode 100644 index 0000000..c30bb13 --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/ajax/form/PanelEdit.html @@ -0,0 +1,47 @@ +<html xmlns:wicket="http://wicket.apache.org"> + +<wicket:panel> + + <div style="height: auto; width: 600px; text-align: center;margin: 0 auto;border: 1px solid silver;"> + + <br> + <br> + Panel Edit (the submit button is in a form) + <br> + <br> + + <form wicket:id="form" > + + .... + Textfield..... + <br> + Textfield..... + <br> + Textfield..... + <br> + <br> + <br> + + When submit is clicked, this panel is remplaced by PanelView + <br> + (the one we come from) + <br> + <br> + But sumit is called twice. + <br> + <br> + + <button wicket:id="submit" class="btn btn-primary btn-sm" type="submit">submit</button> + + </form> + + <br> + <br> + <br> + <br> + + </div> + +</wicket:panel> + +</html> http://git-wip-us.apache.org/repos/asf/wicket/blob/08be805e/wicket-core/src/test/java/org/apache/wicket/ajax/form/PanelEdit.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/form/PanelEdit.java b/wicket-core/src/test/java/org/apache/wicket/ajax/form/PanelEdit.java new file mode 100644 index 0000000..5e0c4fc --- /dev/null +++ b/wicket-core/src/test/java/org/apache/wicket/ajax/form/PanelEdit.java @@ -0,0 +1,60 @@ +/* + * 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.Component; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxButton; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.panel.Panel; + +public class PanelEdit extends Panel { + + public PanelEdit(String id) { + super(id); + + setOutputMarkupId(true); + } + + @Override + protected void onInitialize() { + super.onInitialize(); + + Form<Void> form = new Form<>("form", null); + add(form); + + form.add(createSubmitButton()); + } + + private AjaxButton createSubmitButton() { + + AjaxButton submit = new AjaxButton("submit") { + + protected void onSubmit(AjaxRequestTarget target) { + Component currentcomponent = PanelEdit.this; + Component newComponent = new Label(currentcomponent.getId()) + .setOutputMarkupId(true); + currentcomponent.replaceWith(newComponent); + target.add(newComponent); + } + + }; + + return submit; + } +} \ No newline at end of file