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:54 UTC

[1/2] wicket git commit: Form: code formatting (eclipse settings)

Repository: wicket
Updated Branches:
  refs/heads/master 2ecbff661 -> 849cdc2ba


Form: code formatting (eclipse settings)


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

Branch: refs/heads/master
Commit: de7e6fe1fa2132dacb018a58154a07df99a9bc8a
Parents: 2ecbff6
Author: Sebastien Briquet <se...@amadeus.com>
Authored: Tue Apr 21 14:35:53 2015 +0200
Committer: Sebastien <se...@gmail.com>
Committed: Tue Apr 21 22:46:03 2015 +0200

----------------------------------------------------------------------
 .../apache/wicket/markup/html/form/Form.java    | 109 ++++++++++---------
 1 file changed, 58 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/de7e6fe1/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 aa6ba63..a871f1e 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
@@ -144,8 +144,10 @@ import org.slf4j.LoggerFactory;
  * @param <T>
  *            The model object type
  */
-public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
-	IGenericComponent<T>
+public class Form<T> extends WebMarkupContainer
+	implements
+		IFormSubmitListener,
+		IGenericComponent<T>
 {
 	private static final String HIDDEN_DIV_START = "<div style=\"width:0px;height:0px;position:absolute;left:-100px;top:-100px;overflow:hidden\">";
 
@@ -221,8 +223,8 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 					{
 						if (form.isEnabledInHierarchy())
 						{
-							if (component.isVisibleInHierarchy()
-								&& component.isEnabledInHierarchy())
+							if (component.isVisibleInHierarchy() &&
+								component.isEnabledInHierarchy())
 							{
 								((IFormModelUpdateListener)component).updateModel();
 							}
@@ -445,8 +447,8 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 					{
 						String name = submittingComponent.getInputName();
 						IRequestParameters parameters = getRequest().getRequestParameters();
-						if ((!parameters.getParameterValue(name).isNull())
-							|| !parameters.getParameterValue(name + ".x").isNull())
+						if ((!parameters.getParameterValue(name).isNull()) ||
+							!parameters.getParameterValue(name + ".x").isNull())
 						{
 							visit.stop(submittingComponent);
 						}
@@ -536,9 +538,12 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 		}
 
 		Form<?> root = getRootForm();
-		return new AppendingStringBuffer("document.getElementById('")
-			.append(root.getHiddenFieldId()).append("').value='").append(url)
-			.append("';document.getElementById('").append(root.getMarkupId())
+		return new AppendingStringBuffer("document.getElementById('").append(
+			root.getHiddenFieldId())
+			.append("').value='")
+			.append(url)
+			.append("';document.getElementById('")
+			.append(root.getMarkupId())
 			.append("').submit();");
 	}
 
@@ -582,9 +587,11 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 
 	/**
 	 * Gets maximum size for each file of an upload.
+	 * 
 	 * @return
 	 */
-	public Bytes getFileMaxSize() {
+	public Bytes getFileMaxSize()
+	{
 		return fileMaxSize;
 	}
 
@@ -682,8 +689,7 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 		if (getRequest().getContainerRequest() instanceof HttpServletRequest)
 		{
 			String desiredMethod = getMethod();
-			String actualMethod = ((HttpServletRequest)getRequest().getContainerRequest())
-				.getMethod();
+			String actualMethod = ((HttpServletRequest)getRequest().getContainerRequest()).getMethod();
 			if (!actualMethod.equalsIgnoreCase(desiredMethod))
 			{
 				MethodMismatchResponse response = onMethodMismatch();
@@ -694,8 +700,8 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 					case CONTINUE :
 						break;
 					default :
-						throw new IllegalStateException("Invalid "
-							+ MethodMismatchResponse.class.getName() + " value: " + response);
+						throw new IllegalStateException("Invalid " +
+							MethodMismatchResponse.class.getName() + " value: " + response);
 				}
 			}
 		}
@@ -735,7 +741,8 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 			// Tells FormComponents that a new user input has come
 			inputChanged();
 
-			String url = getRequest().getRequestParameters().getParameterValue(getHiddenFieldId())
+			String url = getRequest().getRequestParameters()
+				.getParameterValue(getHiddenFieldId())
 				.toString();
 			if (!Strings.isEmpty(url))
 			{
@@ -750,8 +757,8 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 
 					if (submitter instanceof IFormSubmittingComponent)
 					{
-						IFormSubmittingComponent submittingComponent = (IFormSubmittingComponent) submitter;
-						Component component = (Component) submitter;
+						IFormSubmittingComponent submittingComponent = (IFormSubmittingComponent)submitter;
+						Component component = (Component)submitter;
 
 						if (!component.isVisibleInHierarchy())
 						{
@@ -904,8 +911,7 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 	 * 
 	 * @param submittingComponent
 	 *            component responsible for submitting the form, or <code>null</code> if none (eg
-	 *            the form has been submitted via the enter key or javascript calling
-	 *            form.submit())
+	 *            the form has been submitted via the enter key or javascript calling form.submit())
 	 * 
 	 * @see #delegateSubmit(IFormSubmitter) for an easy way to process submitting component in the
 	 *      default manner
@@ -1057,9 +1063,11 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 
 	/**
 	 * Sets maximum size of each file in upload request.
+	 * 
 	 * @param fileMaxSize
 	 */
-	public void setFileMaxSize(Bytes fileMaxSize) {
+	public void setFileMaxSize(Bytes fileMaxSize)
+	{
 		this.fileMaxSize = fileMaxSize;
 	}
 
@@ -1145,7 +1153,8 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 			@Override
 			public void component(final Component component, final IVisit<Boolean> visit)
 			{
-				if (component.isVisibleInHierarchy() && component.isEnabledInHierarchy() && component.hasErrorMessage())
+				if (component.isVisibleInHierarchy() && component.isEnabledInHierarchy() &&
+					component.hasErrorMessage())
 				{
 					visit.stop(true);
 				}
@@ -1223,8 +1232,7 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 		buffer.append(defaultSubmittingComponent.getInputName());
 		buffer.append("\" onclick=\" var b=document.getElementById('");
 		buffer.append(submittingComponent.getMarkupId());
-		buffer
-			.append("'); if (b!=null&amp;&amp;b.onclick!=null&amp;&amp;typeof(b.onclick) != 'undefined') {  var r = Wicket.bind(b.onclick, b)(); if (r != false) b.click(); } else { b.click(); };  return false;\" ");
+		buffer.append("'); if (b!=null&amp;&amp;b.onclick!=null&amp;&amp;typeof(b.onclick) != 'undefined') {  var r = Wicket.bind(b.onclick, b)(); if (r != false) b.click(); } else { b.click(); };  return false;\" ");
 		buffer.append(" />");
 
 		// close div
@@ -1401,7 +1409,8 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 			try
 			{
 				ServletWebRequest request = (ServletWebRequest)getRequest();
-				final MultipartServletWebRequest multipartWebRequest = request.newMultipartWebRequest(getMaxSize(), getPage().getId());
+				final MultipartServletWebRequest multipartWebRequest = request.newMultipartWebRequest(
+					getMaxSize(), getPage().getId());
 				multipartWebRequest.setFileMaxSize(getFileMaxSize());
 				multipartWebRequest.parseFileParts();
 
@@ -1684,7 +1693,8 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 	}
 
 	/*
-	 * Writes the markup for the hidden input field and default button field if applicable to the current response.
+	 * Writes the markup for the hidden input field and default button field if applicable to the
+	 * current response.
 	 */
 	public final void writeHiddenFields()
 	{
@@ -1716,8 +1726,8 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 		if (defaultSubmittingComponent instanceof Component)
 		{
 			final Component submittingComponent = (Component)defaultSubmittingComponent;
-			if (submittingComponent.isVisibleInHierarchy()
-					&& submittingComponent.isEnabledInHierarchy())
+			if (submittingComponent.isVisibleInHierarchy() &&
+				submittingComponent.isEnabledInHierarchy())
 			{
 				appendDefaultButtonField();
 			}
@@ -1735,8 +1745,10 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 		{
 			String[] pair = Strings.split(param, '=');
 
-			buffer.append("<input type=\"hidden\" name=\"").append(recode(pair[0]))
-				.append("\" value=\"").append(pair.length > 1 ? recode(pair[1]) : "")
+			buffer.append("<input type=\"hidden\" name=\"")
+				.append(recode(pair[0]))
+				.append("\" value=\"")
+				.append(pair.length > 1 ? recode(pair[1]) : "")
 				.append("\" />");
 		}
 	}
@@ -1870,8 +1882,8 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 	}
 
 	/**
-	 * Calls {@linkplain #onValidateModelObjects()} on this form and all
-	 * nested forms that are visible and enabled
+	 * Calls {@linkplain #onValidateModelObjects()} on this form and all nested forms that are
+	 * visible and enabled
 	 */
 	private void internalOnValidateModelObjects()
 	{
@@ -1975,10 +1987,10 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 				{
 					if (log.isWarnEnabled())
 					{
-						log.warn("IFormValidator in form `"
-							+ getPageRelativePath()
-							+ "` depends on a component that has been removed from the page or is no longer visible. "
-							+ "Offending component id `" + dependent.getId() + "`.");
+						log.warn("IFormValidator in form `" +
+							getPageRelativePath() +
+							"` depends on a component that has been removed from the page or is no longer visible. " +
+							"Offending component id `" + dependent.getId() + "`.");
 					}
 					validate = false;
 					break;
@@ -2090,10 +2102,8 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 			// register some metadata so we can later properly handle multipart ajax posts for
 			// embedded forms
 			registerJavaScriptNamespaces(response);
-			response
-				.render(JavaScriptHeaderItem.forScript("Wicket.Forms[\"" + getMarkupId()
-					+ "\"]={multipart:true};", Form.class.getName() + '.' + getMarkupId()
-					+ ".metadata"));
+			response.render(JavaScriptHeaderItem.forScript("Wicket.Forms[\"" + getMarkupId() +
+				"\"]={multipart:true};", Form.class.getName() + '.' + getMarkupId() + ".metadata"));
 		}
 	}
 
@@ -2104,11 +2114,9 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 	 */
 	protected void registerJavaScriptNamespaces(IHeaderResponse response)
 	{
-		response
-			.render(JavaScriptHeaderItem
-				.forScript(
-					"if (typeof(Wicket)=='undefined') { Wicket={}; } if (typeof(Wicket.Forms)=='undefined') { Wicket.Forms={}; }",
-					Form.class.getName()));
+		response.render(JavaScriptHeaderItem.forScript(
+			"if (typeof(Wicket)=='undefined') { Wicket={}; } if (typeof(Wicket.Forms)=='undefined') { Wicket.Forms={}; }",
+			Form.class.getName()));
 	}
 
 	/**
@@ -2127,8 +2135,8 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 		{
 			inputName.prepend(id);
 			c = c.getParent();
-			if (c == null || (c instanceof Form<?> && ((Form<?>)c).isRootForm())
-				|| c instanceof Page)
+			if (c == null || (c instanceof Form<?> && ((Form<?>)c).isRootForm()) ||
+				c instanceof Page)
 			{
 				break;
 			}
@@ -2138,9 +2146,9 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 
 		/*
 		 * Certain input names causes problems with JavaScript. If the input name would cause a
-		 * problem, we create a replacement unique name by prefixing the name with a path that
-		 * would otherwise never be used (blank id in path).
-		 *
+		 * problem, we create a replacement unique name by prefixing the name with a path that would
+		 * otherwise never be used (blank id in path).
+		 * 
 		 * Input names must start with [A-Za-z] according to HTML 4.01 spec. HTML 5 allows almost
 		 * anything.
 		 */
@@ -2160,8 +2168,7 @@ public class Form<T> extends WebMarkupContainer implements IFormSubmitListener,
 	 * 
 	 * @author igor
 	 */
-	public static enum MethodMismatchResponse
-	{
+	public static enum MethodMismatchResponse {
 		/**
 		 * Continue processing.
 		 */


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));
>         }
>  }
>
>

[2/2] wicket git commit: Added Form#wantSubmitOnParentFormSubmit & UnitTest

Posted by sb...@apache.org.
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));
 	}
 }