You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sb...@apache.org on 2015/04/21 22:56:55 UTC
[2/2] wicket git commit: Added Form#wantSubmitOnParentFormSubmit &
UnitTest
Added Form#wantSubmitOnParentFormSubmit & UnitTest
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/849cdc2b
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/849cdc2b
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/849cdc2b
Branch: refs/heads/master
Commit: 849cdc2ba76093b61a623da75b6999d575c77b4b
Parents: de7e6fe
Author: Sebastien Briquet <se...@amadeus.com>
Authored: Tue Apr 21 14:37:19 2015 +0200
Committer: Sebastien <se...@gmail.com>
Committed: Tue Apr 21 22:46:16 2015 +0200
----------------------------------------------------------------------
.../apache/wicket/markup/html/form/Form.java | 35 +++++++----
.../markup/html/form/NestedFormSubmitTest.java | 64 +++++++++++++-------
2 files changed, 64 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/849cdc2b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
index a871f1e..f3fdbb8 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
@@ -895,11 +895,23 @@ public class Form<T> extends WebMarkupContainer
*
* @return Whether this form wants to be submitted too if a nested form is submitted.
*/
- public boolean wantSubmitOnNestedFormSubmit()
+ // TODO wicket-7 migration guide: changed from public to protected
+ protected boolean wantSubmitOnNestedFormSubmit()
{
return false;
}
+ /**
+ * Whether this *nested* form wants to be submitted when parent form is submitted. By default,
+ * this is true, so when a parent form is submitted, the nested form is also submitted. If this
+ * method is overridden to return false, it will not be validated, processed nor submitted.
+ *
+ * @return {@code true} by default
+ */
+ protected boolean wantSubmitOnParentFormSubmit()
+ {
+ return true;
+ }
/**
* Process the form. Though you can override this method to provide your own algorithm, it is
@@ -1011,7 +1023,8 @@ public class Form<T> extends WebMarkupContainer
public void component(final Component component, final IVisit<Void> visit)
{
Form<?> form = (Form<?>)component;
- if (form.isEnabledInHierarchy() && isVisibleInHierarchy())
+ if (form.isEnabledInHierarchy() && form.isVisibleInHierarchy() &&
+ form.wantSubmitOnParentFormSubmit())
{
form.setFlag(FLAG_SUBMITTED, true);
return;
@@ -1280,7 +1293,7 @@ public class Form<T> extends WebMarkupContainer
@Override
public void component(Form<?> form, IVisit<Void> visit)
{
- if (form.isEnabledInHierarchy() && form.isVisibleInHierarchy())
+ if (form.isSubmitted())
{
forms.add(form);
}
@@ -1525,7 +1538,7 @@ public class Form<T> extends WebMarkupContainer
@Override
public void component(final Form<?> form, final IVisit<Void> visit)
{
- if (form.isEnabledInHierarchy() && form.isVisibleInHierarchy())
+ if (form.isSubmitted())
{
form.internalMarkFormComponentsValid();
}
@@ -1692,7 +1705,7 @@ public class Form<T> extends WebMarkupContainer
super.onComponentTagBody(markupStream, openTag);
}
- /*
+ /**
* Writes the markup for the hidden input field and default button field if applicable to the
* current response.
*/
@@ -1829,10 +1842,9 @@ public class Form<T> extends WebMarkupContainer
@Override
public void component(final Form<?> form, final IVisit<Void> visit)
{
- if (form.isEnabledInHierarchy() && form.isVisibleInHierarchy())
+ if (form.isSubmitted())
{
form.internalUpdateFormComponentModels();
-
}
else
{
@@ -1891,11 +1903,11 @@ public class Form<T> extends WebMarkupContainer
visitChildren(Form.class, new IVisitor<Form<?>, Void>()
{
@Override
- public void component(Form<?> nestedForm, IVisit<Void> visit)
+ public void component(Form<?> form, IVisit<Void> visit)
{
- if (nestedForm.isEnabledInHierarchy() && nestedForm.isVisibleInHierarchy())
+ if (form.isSubmitted())
{
- nestedForm.onValidateModelObjects();
+ form.onValidateModelObjects();
}
else
{
@@ -2037,7 +2049,7 @@ public class Form<T> extends WebMarkupContainer
return;
}
- if (form.isEnabledInHierarchy() && form.isVisibleInHierarchy())
+ if (form.isSubmitted())
{
form.validateComponents();
form.validateFormValidators();
@@ -2047,7 +2059,6 @@ public class Form<T> extends WebMarkupContainer
}, new ClassVisitFilter(Form.class));
}
-
/**
* Allows to customize input names of form components inside this form.
*
http://git-wip-us.apache.org/repos/asf/wicket/blob/849cdc2b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/NestedFormSubmitTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/NestedFormSubmitTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/NestedFormSubmitTest.java
index c325f1f..b7c4417 100644
--- a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/NestedFormSubmitTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/NestedFormSubmitTest.java
@@ -33,12 +33,15 @@ public class NestedFormSubmitTest extends WicketTestCase
private final IModel<Boolean> submitted;
private final Button submit;
private final boolean wantInclusion;
+ private final boolean wantExclusion;
- TestForm(String id, IModel<Boolean> submitted, boolean wantInclusion)
+ TestForm(String id, IModel<Boolean> submitted, boolean wantInclusion, boolean wantExclusion)
{
super(id);
this.submitted = submitted;
this.wantInclusion = wantInclusion;
+ this.wantExclusion = wantExclusion;
+
submit = new Button("submit");
add(submit);
}
@@ -55,23 +58,30 @@ public class NestedFormSubmitTest extends WicketTestCase
{
return wantInclusion;
}
+
+ @Override
+ public boolean wantSubmitOnParentFormSubmit()
+ {
+ return wantExclusion;
+ }
}
public class TestPage extends WebPage
{
- private final TestForm outer;
- private final TestForm middle;
- private final TestForm inner;
+ private final TestForm<?> outer;
+ private final TestForm<?> middle;
+ private final TestForm<?> inner;
public TestPage(IModel<Boolean> submittedOuter, boolean outerWantsInclusion,
IModel<Boolean> submittedMiddle, boolean middleWantsInclusion,
- IModel<Boolean> submittedInner)
+ boolean middleWantsExclusion, IModel<Boolean> submittedInner)
{
- outer = new TestForm("outer", submittedOuter, outerWantsInclusion);
+ outer = new TestForm<Void>("outer", submittedOuter, outerWantsInclusion, true);
this.add(outer);
- middle = new TestForm("middle", submittedMiddle, middleWantsInclusion);
+ middle = new TestForm<Void>("middle", submittedMiddle, middleWantsInclusion,
+ middleWantsExclusion);
outer.add(middle);
- inner = new TestForm("inner", submittedInner, false);
+ inner = new TestForm<Void>("inner", submittedInner, false, true);
middle.add(inner);
}
}
@@ -97,13 +107,6 @@ public class NestedFormSubmitTest extends WicketTestCase
submittedOuter.setObject(false);
}
- @Test
- public void testDefaultOuterSubmitShouldSubmitAll() throws Exception
- {
- startPage(false, false);
- assertFormSubmitOuter(true, true, true);
- }
-
private void assertFormSubmitOuter(boolean expectSubmittedOuter, boolean expectSubmittedMiddle,
boolean expectSubmittedInner)
{
@@ -137,37 +140,44 @@ public class NestedFormSubmitTest extends WicketTestCase
}
@Test
+ public void testDefaultOuterSubmitShouldSubmitAll() throws Exception
+ {
+ startPage(false, false, true);
+ assertFormSubmitOuter(true, true, true);
+ }
+
+ @Test
public void testDefaultMiddleSubmitShouldSubmitMiddleAndInner() throws Exception
{
- startPage(false, false);
+ startPage(false, false, true);
assertFormSubmitMiddle(false, true, true);
}
@Test
public void testDefaultInnerSubmitShouldSubmitOnlyInner() throws Exception
{
- startPage(false, false);
+ startPage(false, false, true);
assertFormSubmitInner(false, false, true);
}
@Test
public void testWithOuterInclusionOuterIsSubmittedOnMiddleSubmit() throws Exception
{
- startPage(true, false);
+ startPage(true, false, true);
assertFormSubmitMiddle(true, true, true);
}
@Test
public void testWithOuterInclusionOuterIsSubmittedOnInnerSubmit() throws Exception
{
- startPage(true, false);
+ startPage(true, false, true);
assertFormSubmitInner(true, true, true);
}
@Test
public void testWithMiddleInclusionMiddleIsSubmittedOnInnerSubmit() throws Exception
{
- startPage(false, true);
+ startPage(false, true, true);
assertFormSubmitInner(false, true, true);
}
@@ -175,13 +185,21 @@ public class NestedFormSubmitTest extends WicketTestCase
public void testWithMiddleAndOuterInclusionMiddleAndOuterIsSubmittedOnInnerSubmit()
throws Exception
{
- startPage(true, true);
+ startPage(true, true, true);
assertFormSubmitInner(true, true, true);
}
- private void startPage(boolean outerWantsInclusion, boolean middleWantsInclusion)
+ @Test
+ public void testWithMiddleExclusionAndOuterIsSubmitted() throws Exception
+ {
+ startPage(false, false, false);
+ assertFormSubmitOuter(true, false, false);
+ }
+
+ private void startPage(boolean outerWantsInclusion, boolean middleWantsInclusion,
+ boolean middleWantsExclusion)
{
page = (TestPage)tester.startPage(new TestPage(submittedOuter, outerWantsInclusion,
- submittedMiddle, middleWantsInclusion, submittedInner));
+ submittedMiddle, middleWantsInclusion, middleWantsExclusion, submittedInner));
}
}
Re: [2/2] wicket git commit: Added Form#wantSubmitOnParentFormSubmit
& UnitTest
Posted by Sebastien Briquet <sb...@apache.org>.
Oops sorry, I forgot to reference the issue in the commit description !! :/
On Tue, Apr 21, 2015 at 10:56 PM, <sb...@apache.org> wrote:
> Added Form#wantSubmitOnParentFormSubmit & UnitTest
>
>
> Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
> Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/849cdc2b
> Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/849cdc2b
> Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/849cdc2b
>
> Branch: refs/heads/master
> Commit: 849cdc2ba76093b61a623da75b6999d575c77b4b
> Parents: de7e6fe
> Author: Sebastien Briquet <se...@amadeus.com>
> Authored: Tue Apr 21 14:37:19 2015 +0200
> Committer: Sebastien <se...@gmail.com>
> Committed: Tue Apr 21 22:46:16 2015 +0200
>
> ----------------------------------------------------------------------
> .../apache/wicket/markup/html/form/Form.java | 35 +++++++----
> .../markup/html/form/NestedFormSubmitTest.java | 64 +++++++++++++-------
> 2 files changed, 64 insertions(+), 35 deletions(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/849cdc2b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
> ----------------------------------------------------------------------
> diff --git
> a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
> b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
> index a871f1e..f3fdbb8 100644
> ---
> a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
> +++
> b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java
> @@ -895,11 +895,23 @@ public class Form<T> extends WebMarkupContainer
> *
> * @return Whether this form wants to be submitted too if a nested
> form is submitted.
> */
> - public boolean wantSubmitOnNestedFormSubmit()
> + // TODO wicket-7 migration guide: changed from public to protected
> + protected boolean wantSubmitOnNestedFormSubmit()
> {
> return false;
> }
>
> + /**
> + * Whether this *nested* form wants to be submitted when parent
> form is submitted. By default,
> + * this is true, so when a parent form is submitted, the nested
> form is also submitted. If this
> + * method is overridden to return false, it will not be validated,
> processed nor submitted.
> + *
> + * @return {@code true} by default
> + */
> + protected boolean wantSubmitOnParentFormSubmit()
> + {
> + return true;
> + }
>
> /**
> * Process the form. Though you can override this method to
> provide your own algorithm, it is
> @@ -1011,7 +1023,8 @@ public class Form<T> extends WebMarkupContainer
> public void component(final Component component,
> final IVisit<Void> visit)
> {
> Form<?> form = (Form<?>)component;
> - if (form.isEnabledInHierarchy() &&
> isVisibleInHierarchy())
> + if (form.isEnabledInHierarchy() &&
> form.isVisibleInHierarchy() &&
> +
> form.wantSubmitOnParentFormSubmit())
> {
> form.setFlag(FLAG_SUBMITTED, true);
> return;
> @@ -1280,7 +1293,7 @@ public class Form<T> extends WebMarkupContainer
> @Override
> public void component(Form<?> form, IVisit<Void>
> visit)
> {
> - if (form.isEnabledInHierarchy() &&
> form.isVisibleInHierarchy())
> + if (form.isSubmitted())
> {
> forms.add(form);
> }
> @@ -1525,7 +1538,7 @@ public class Form<T> extends WebMarkupContainer
> @Override
> public void component(final Form<?> form, final
> IVisit<Void> visit)
> {
> - if (form.isEnabledInHierarchy() &&
> form.isVisibleInHierarchy())
> + if (form.isSubmitted())
> {
>
> form.internalMarkFormComponentsValid();
> }
> @@ -1692,7 +1705,7 @@ public class Form<T> extends WebMarkupContainer
> super.onComponentTagBody(markupStream, openTag);
> }
>
> - /*
> + /**
> * Writes the markup for the hidden input field and default button
> field if applicable to the
> * current response.
> */
> @@ -1829,10 +1842,9 @@ public class Form<T> extends WebMarkupContainer
> @Override
> public void component(final Form<?> form, final
> IVisit<Void> visit)
> {
> - if (form.isEnabledInHierarchy() &&
> form.isVisibleInHierarchy())
> + if (form.isSubmitted())
> {
>
> form.internalUpdateFormComponentModels();
> -
> }
> else
> {
> @@ -1891,11 +1903,11 @@ public class Form<T> extends WebMarkupContainer
> visitChildren(Form.class, new IVisitor<Form<?>, Void>()
> {
> @Override
> - public void component(Form<?> nestedForm,
> IVisit<Void> visit)
> + public void component(Form<?> form, IVisit<Void>
> visit)
> {
> - if (nestedForm.isEnabledInHierarchy() &&
> nestedForm.isVisibleInHierarchy())
> + if (form.isSubmitted())
> {
> -
> nestedForm.onValidateModelObjects();
> + form.onValidateModelObjects();
> }
> else
> {
> @@ -2037,7 +2049,7 @@ public class Form<T> extends WebMarkupContainer
> return;
> }
>
> - if (form.isEnabledInHierarchy() &&
> form.isVisibleInHierarchy())
> + if (form.isSubmitted())
> {
> form.validateComponents();
> form.validateFormValidators();
> @@ -2047,7 +2059,6 @@ public class Form<T> extends WebMarkupContainer
> }, new ClassVisitFilter(Form.class));
> }
>
> -
> /**
> * Allows to customize input names of form components inside this
> form.
> *
>
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/849cdc2b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/NestedFormSubmitTest.java
> ----------------------------------------------------------------------
> diff --git
> a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/NestedFormSubmitTest.java
> b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/NestedFormSubmitTest.java
> index c325f1f..b7c4417 100644
> ---
> a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/NestedFormSubmitTest.java
> +++
> b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/NestedFormSubmitTest.java
> @@ -33,12 +33,15 @@ public class NestedFormSubmitTest extends
> WicketTestCase
> private final IModel<Boolean> submitted;
> private final Button submit;
> private final boolean wantInclusion;
> + private final boolean wantExclusion;
>
> - TestForm(String id, IModel<Boolean> submitted, boolean
> wantInclusion)
> + TestForm(String id, IModel<Boolean> submitted, boolean
> wantInclusion, boolean wantExclusion)
> {
> super(id);
> this.submitted = submitted;
> this.wantInclusion = wantInclusion;
> + this.wantExclusion = wantExclusion;
> +
> submit = new Button("submit");
> add(submit);
> }
> @@ -55,23 +58,30 @@ public class NestedFormSubmitTest extends
> WicketTestCase
> {
> return wantInclusion;
> }
> +
> + @Override
> + public boolean wantSubmitOnParentFormSubmit()
> + {
> + return wantExclusion;
> + }
> }
>
> public class TestPage extends WebPage
> {
> - private final TestForm outer;
> - private final TestForm middle;
> - private final TestForm inner;
> + private final TestForm<?> outer;
> + private final TestForm<?> middle;
> + private final TestForm<?> inner;
>
> public TestPage(IModel<Boolean> submittedOuter, boolean
> outerWantsInclusion,
> IModel<Boolean> submittedMiddle, boolean
> middleWantsInclusion,
> - IModel<Boolean> submittedInner)
> + boolean middleWantsExclusion, IModel<Boolean>
> submittedInner)
> {
> - outer = new TestForm("outer", submittedOuter,
> outerWantsInclusion);
> + outer = new TestForm<Void>("outer",
> submittedOuter, outerWantsInclusion, true);
> this.add(outer);
> - middle = new TestForm("middle", submittedMiddle,
> middleWantsInclusion);
> + middle = new TestForm<Void>("middle",
> submittedMiddle, middleWantsInclusion,
> + middleWantsExclusion);
> outer.add(middle);
> - inner = new TestForm("inner", submittedInner,
> false);
> + inner = new TestForm<Void>("inner",
> submittedInner, false, true);
> middle.add(inner);
> }
> }
> @@ -97,13 +107,6 @@ public class NestedFormSubmitTest extends
> WicketTestCase
> submittedOuter.setObject(false);
> }
>
> - @Test
> - public void testDefaultOuterSubmitShouldSubmitAll() throws
> Exception
> - {
> - startPage(false, false);
> - assertFormSubmitOuter(true, true, true);
> - }
> -
> private void assertFormSubmitOuter(boolean expectSubmittedOuter,
> boolean expectSubmittedMiddle,
> boolean expectSubmittedInner)
> {
> @@ -137,37 +140,44 @@ public class NestedFormSubmitTest extends
> WicketTestCase
> }
>
> @Test
> + public void testDefaultOuterSubmitShouldSubmitAll() throws
> Exception
> + {
> + startPage(false, false, true);
> + assertFormSubmitOuter(true, true, true);
> + }
> +
> + @Test
> public void testDefaultMiddleSubmitShouldSubmitMiddleAndInner()
> throws Exception
> {
> - startPage(false, false);
> + startPage(false, false, true);
> assertFormSubmitMiddle(false, true, true);
> }
>
> @Test
> public void testDefaultInnerSubmitShouldSubmitOnlyInner() throws
> Exception
> {
> - startPage(false, false);
> + startPage(false, false, true);
> assertFormSubmitInner(false, false, true);
> }
>
> @Test
> public void testWithOuterInclusionOuterIsSubmittedOnMiddleSubmit()
> throws Exception
> {
> - startPage(true, false);
> + startPage(true, false, true);
> assertFormSubmitMiddle(true, true, true);
> }
>
> @Test
> public void testWithOuterInclusionOuterIsSubmittedOnInnerSubmit()
> throws Exception
> {
> - startPage(true, false);
> + startPage(true, false, true);
> assertFormSubmitInner(true, true, true);
> }
>
> @Test
> public void
> testWithMiddleInclusionMiddleIsSubmittedOnInnerSubmit() throws Exception
> {
> - startPage(false, true);
> + startPage(false, true, true);
> assertFormSubmitInner(false, true, true);
> }
>
> @@ -175,13 +185,21 @@ public class NestedFormSubmitTest extends
> WicketTestCase
> public void
> testWithMiddleAndOuterInclusionMiddleAndOuterIsSubmittedOnInnerSubmit()
> throws Exception
> {
> - startPage(true, true);
> + startPage(true, true, true);
> assertFormSubmitInner(true, true, true);
> }
>
> - private void startPage(boolean outerWantsInclusion, boolean
> middleWantsInclusion)
> + @Test
> + public void testWithMiddleExclusionAndOuterIsSubmitted() throws
> Exception
> + {
> + startPage(false, false, false);
> + assertFormSubmitOuter(true, false, false);
> + }
> +
> + private void startPage(boolean outerWantsInclusion, boolean
> middleWantsInclusion,
> + boolean middleWantsExclusion)
> {
> page = (TestPage)tester.startPage(new
> TestPage(submittedOuter, outerWantsInclusion,
> - submittedMiddle, middleWantsInclusion,
> submittedInner));
> + submittedMiddle, middleWantsInclusion,
> middleWantsExclusion, submittedInner));
> }
> }
>
>