You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2021/08/16 10:47:47 UTC

[wicket] branch wicket-8.x updated (db80c7e -> bb69ae4)

This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a change to branch wicket-8.x
in repository https://gitbox.apache.org/repos/asf/wicket.git.


    from db80c7e  WICKET-6908 adjusted test to junit 4
     new 3b7dd47  INFRA-22136 Replace bintray.io with apache.jfrog.io
     new 8bc3614  WICKET-6914  Visibility change of "File Upload" via ajax causes "missing" form-data
     new cc34ecf  Simplify JUnit assertions
     new a0b2f62  WICKET-6914 Visibility change of "File Upload" via ajax causes "missing" form-data
     new bb69ae4  WICKET-6914 Update test to JUnit 4.x

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../http/MultipartFormComponentListener.java       | 52 ++++++++++++++
 .../wicket/protocol/http/WebApplication.java       |  4 +-
 .../wicket/markup/html/form/FormMultiPartTest.java | 26 +++----
 .../wicket/markup/html/form/MultiPartFormPage.java |  4 +-
 .../http/MultipartFormComponentListenerBean.java}  | 63 ++++++-----------
 .../http/MultipartFormComponentListenerPage.html   | 17 +++++
 .../http/MultipartFormComponentListenerPage.java   | 80 ++++++++++++++++++++++
 .../http/MultipartFormComponentListenerTest.java   | 48 +++++++++++++
 wicket-examples/pom.xml                            |  2 +-
 9 files changed, 237 insertions(+), 59 deletions(-)
 create mode 100644 wicket-core/src/main/java/org/apache/wicket/protocol/http/MultipartFormComponentListener.java
 copy wicket-core/src/test/java/org/apache/wicket/{util/tester/apps_1/Book.java => protocol/http/MultipartFormComponentListenerBean.java} (58%)
 create mode 100644 wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerPage.html
 create mode 100644 wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerPage.java
 create mode 100644 wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerTest.java

[wicket] 04/05: WICKET-6914 Visibility change of "File Upload" via ajax causes "missing" form-data

Posted by mg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch wicket-8.x
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit a0b2f62901985961e8573747ea5771d4f983d6ec
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Mon Aug 16 12:17:21 2021 +0300

    WICKET-6914 Visibility change of "File Upload" via ajax causes "missing" form-data
    
    Update test expectations.
    FormComponent#isMultipart() is called now by MultipartFormComponentListener in Ajax requests
    
    (cherry picked from commit f9c98737fb9ed798c9c8cb25e87c3f7f6e87bfb2)
---
 .../java/org/apache/wicket/markup/html/form/FormMultiPartTest.java    | 4 ++--
 .../java/org/apache/wicket/markup/html/form/MultiPartFormPage.java    | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/FormMultiPartTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/FormMultiPartTest.java
index c6aebe4..c7cdb8e 100644
--- a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/FormMultiPartTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/FormMultiPartTest.java
@@ -70,12 +70,12 @@ public class FormMultiPartTest extends WicketTestCase
 
 		page.multiPart = true;
 		tester.executeAjaxEvent(page.button1, "click");
-		assertEquals(2, page.asked);
+		assertEquals(3, page.asked);
 		assertTrue(page.form.isMultiPart());
 
 		page.multiPart = false;
 		tester.executeAjaxEvent(page.button1, "click");
-		assertEquals(3, page.asked);
+		assertEquals(5, page.asked);
 		assertFalse(page.form.isMultiPart());
 	}
 }
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/MultiPartFormPage.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/MultiPartFormPage.java
index e354ff9..5891e13 100644
--- a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/MultiPartFormPage.java
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/MultiPartFormPage.java
@@ -49,7 +49,7 @@ public class MultiPartFormPage extends WebPage
 		form = new Form<Void>("form");
 		add(form.setOutputMarkupId(true));
 		
-		input = new TextField<String>("input", Model.of(""))
+		input = new TextField<>("input", Model.of(""))
 		{
 			@Override
 			public boolean isMultiPart() {
@@ -80,4 +80,4 @@ public class MultiPartFormPage extends WebPage
 		};
 		form.add(button2);
 	}
-}
\ No newline at end of file
+}

[wicket] 05/05: WICKET-6914 Update test to JUnit 4.x

Posted by mg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch wicket-8.x
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit bb69ae455f5ab9e3213d1f31ef9267b18d97e675
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Mon Aug 16 13:47:20 2021 +0300

    WICKET-6914 Update test to JUnit 4.x
---
 .../wicket/protocol/http/MultipartFormComponentListenerTest.java | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerTest.java
index b5cbf26..cb75df7 100644
--- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerTest.java
@@ -16,21 +16,18 @@
  */
 package org.apache.wicket.protocol.http;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
 import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.util.tester.TagTester;
 import org.apache.wicket.util.tester.WicketTestCase;
-import org.junit.jupiter.api.Test;
+import org.junit.Test;
 
 /**
  * https://issues.apache.org/jira/browse/WICKET-6914
  */
-class MultipartFormComponentListenerTest extends WicketTestCase
+public class MultipartFormComponentListenerTest extends WicketTestCase
 {
     @Test
-    void updateFormEnctype()
+    public void updateFormEnctype()
     {
         tester.startPage(MultipartFormComponentListenerPage.class);
         tester.assertRenderedPage(MultipartFormComponentListenerPage.class);

[wicket] 01/05: INFRA-22136 Replace bintray.io with apache.jfrog.io

Posted by mg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch wicket-8.x
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit 3b7dd47d6419e6c06735dac7b6e94fea74987297
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Fri Jul 23 09:20:54 2021 +0300

    INFRA-22136 Replace bintray.io with apache.jfrog.io
    
    (cherry picked from commit e3958b25642b90dbe011419a5aa0e489ce7774b3)
---
 wicket-examples/pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/wicket-examples/pom.xml b/wicket-examples/pom.xml
index 1af1378..b44d224 100644
--- a/wicket-examples/pom.xml
+++ b/wicket-examples/pom.xml
@@ -324,7 +324,7 @@
 						<artifactId>dockerfile-maven-plugin</artifactId>
 						<version>${dockerfile-maven-plugin.version}</version>
 						<configuration>
-							<repository>apache-docker-wicket-docker.bintray.io/wicket-examples</repository>
+							<repository>apache.jfrog.io/wicket-docker/wicket-examples</repository>
 							<tag>LATEST-8</tag>
 						</configuration>
 						<executions>

[wicket] 03/05: Simplify JUnit assertions

Posted by mg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch wicket-8.x
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit cc34ecf0118ff2adfec04de53db817859ec7d37b
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Mon Aug 16 12:12:22 2021 +0300

    Simplify JUnit assertions
    
    Non-functional change!
    
    (cherry picked from commit 66b35ade4b3999025e58580bc683e7f7c32cafa9)
---
 .../wicket/markup/html/form/FormMultiPartTest.java | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/FormMultiPartTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/FormMultiPartTest.java
index cb8effb..c6aebe4 100644
--- a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/FormMultiPartTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/FormMultiPartTest.java
@@ -34,7 +34,7 @@ public class FormMultiPartTest extends WicketTestCase
 
 		assertEquals(0, page.asked);
 
-		assertEquals(true, page.form.isMultiPart());
+		assertTrue(page.form.isMultiPart());
 	}
 
 	@Test
@@ -45,17 +45,17 @@ public class FormMultiPartTest extends WicketTestCase
 		page.multiPart = false;
 		tester.startPage(page);
 		assertEquals(1, page.asked);
-		assertEquals(false, page.form.isMultiPart());
-		
+		assertFalse(page.form.isMultiPart());
+
 		page.multiPart = true;
 		tester.newFormTester("form").submit(page.button1);
 		assertEquals(2, page.asked);
-		assertEquals(true, page.form.isMultiPart());
-		
+		assertTrue(page.form.isMultiPart());
+
 		page.multiPart = false;
 		tester.newFormTester("form").submit(page.button1);
 		assertEquals(3, page.asked);
-		assertEquals(false, page.form.isMultiPart());		
+		assertFalse(page.form.isMultiPart());
 	}
 	
 	@Test
@@ -66,16 +66,16 @@ public class FormMultiPartTest extends WicketTestCase
 		page.multiPart = false;
 		tester.startPage(page);
 		assertEquals(1, page.asked);
-		assertEquals(false, page.form.isMultiPart());
-		
+		assertFalse(page.form.isMultiPart());
+
 		page.multiPart = true;
 		tester.executeAjaxEvent(page.button1, "click");
 		assertEquals(2, page.asked);
-		assertEquals(true, page.form.isMultiPart());
-		
+		assertTrue(page.form.isMultiPart());
+
 		page.multiPart = false;
 		tester.executeAjaxEvent(page.button1, "click");
 		assertEquals(3, page.asked);
-		assertEquals(false, page.form.isMultiPart());		
+		assertFalse(page.form.isMultiPart());
 	}
 }

[wicket] 02/05: WICKET-6914 Visibility change of "File Upload" via ajax causes "missing" form-data

Posted by mg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch wicket-8.x
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit 8bc3614d67bd5b2aad204a4ec06136dc8df3fcf7
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Mon Aug 16 11:43:36 2021 +0300

    WICKET-6914  Visibility change of "File Upload" via ajax causes "missing" form-data
    
    Update the <form>'s enctype whenever a multipart form component is repainted via Ajax
    
    (cherry picked from commit 06e9f53dbe79a11bf6512263351edc9481dd5619)
---
 .../http/MultipartFormComponentListener.java       | 52 ++++++++++++++
 .../wicket/protocol/http/WebApplication.java       |  4 +-
 .../http/MultipartFormComponentListenerBean.java   | 58 ++++++++++++++++
 .../http/MultipartFormComponentListenerPage.html   | 17 +++++
 .../http/MultipartFormComponentListenerPage.java   | 80 ++++++++++++++++++++++
 .../http/MultipartFormComponentListenerTest.java   | 51 ++++++++++++++
 6 files changed, 261 insertions(+), 1 deletion(-)

diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/MultipartFormComponentListener.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/MultipartFormComponentListener.java
new file mode 100644
index 0000000..f5572ed
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/MultipartFormComponentListener.java
@@ -0,0 +1,52 @@
+/*
+ * 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.protocol.http;
+
+import java.util.Map;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.FormComponent;
+import org.apache.wicket.util.visit.IVisitor;
+
+/**
+ * This listener updates the {@link Form}'s <em>enctype</em> whenever a multipart {@link FormComponent}
+ * is added to the {@code AjaxRequestTarget}.
+ * This is needed because the multipart form component may change its visibility/enablement and thus
+ * change the multipart-ness of the whole form.
+ */
+public class MultipartFormComponentListener implements AjaxRequestTarget.IListener
+{
+	static final String ENCTYPE_URL_ENCODED = "application/x-www-form-urlencoded";
+
+	@Override
+	public void onBeforeRespond(final Map<String, Component> map, final AjaxRequestTarget target)
+	{
+		target.getPage().visitChildren(FormComponent.class, (IVisitor<FormComponent<?>, Void>) (formComponent, visit) -> {
+			if (formComponent.isMultiPart())
+			{
+				Form<?> form = formComponent.getForm();
+				boolean multiPart = form.isMultiPart();
+				String enctype = multiPart ? Form.ENCTYPE_MULTIPART_FORM_DATA : ENCTYPE_URL_ENCODED;
+				target.appendJavaScript(String.format("Wicket.$('%s').form.enctype='%s'",
+						formComponent.getMarkupId(), enctype));
+				visit.stop();
+			}
+		});
+	}
+}
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
index 503f793..ddaf733 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
@@ -757,7 +757,9 @@ public abstract class WebApplication extends Application
 		setSessionStoreProvider(HttpSessionStore::new);
 		setAjaxRequestTargetProvider(AjaxRequestHandler::new);
 
-		getAjaxRequestTargetListeners().add(new AjaxEnclosureListener());
+		AjaxRequestTargetListenerCollection ajaxRequestTargetListeners = getAjaxRequestTargetListeners();
+		ajaxRequestTargetListeners.add(new AjaxEnclosureListener());
+		ajaxRequestTargetListeners.add(new MultipartFormComponentListener());
 
 		// Configure the app.
 		configure();
diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerBean.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerBean.java
new file mode 100644
index 0000000..41b6ca4
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerBean.java
@@ -0,0 +1,58 @@
+/*
+ * 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.protocol.http;
+
+import java.io.Serializable;
+
+public class MultipartFormComponentListenerBean implements Serializable {
+	private String textField;
+	private String dropDown;
+
+	/**
+	 * @return the textField
+	 */
+	public String getTextField() {
+		return textField;
+	}
+
+
+	/**
+	 * @return the dropDown
+	 */
+	public String getDropDown() {
+		return dropDown;
+	}
+
+
+	/**
+	 * @param textField
+	 *                     the textField to set
+	 */
+	public void setTextField(String textField) {
+		this.textField = textField;
+	}
+
+
+	/**
+	 * @param dropDown
+	 *                    the dropDown to set
+	 */
+	public void setDropDown(String dropDown) {
+		this.dropDown = dropDown;
+	}
+
+}
diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerPage.html b/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerPage.html
new file mode 100644
index 0000000..eb741e8
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerPage.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+<meta charset="utf-8" />
+<title>Apache Wicket 6914</title>
+</head>
+<body>
+	<form wicket:id="form">
+		<input type="text" wicket:id="textField" /><br/>
+		<select  wicket:id="dropDown"></select><br/>
+		<input wicket:id="fileUpload" type="file" /><br/> 
+		<input type="submit" value="save" wicket:id="submitButton" /><br/><br/><br/>
+	</form>
+	content of textfield or error: <div wicket:id="label"></div>
+	
+</body>
+</html>
diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerPage.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerPage.java
new file mode 100644
index 0000000..d0b7842
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerPage.java
@@ -0,0 +1,80 @@
+/*
+ * 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.protocol.http;
+
+import java.util.ArrayList;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.Button;
+import org.apache.wicket.markup.html.form.DropDownChoice;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.RequiredTextField;
+import org.apache.wicket.markup.html.form.upload.FileUploadField;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.Model;
+
+public class MultipartFormComponentListenerPage extends WebPage {
+	private static final long serialVersionUID = 1L;
+
+	public MultipartFormComponentListenerPage() {
+		CompoundPropertyModel<MultipartFormComponentListenerBean> model = new CompoundPropertyModel<>(new MultipartFormComponentListenerBean());
+		Form<MultipartFormComponentListenerBean> form = new Form<>("form", model);
+		add(form);
+
+		RequiredTextField<String> textField = new RequiredTextField<>("textField");
+		form.add(textField);
+
+		ArrayList<String> list = new ArrayList<>();
+		list.add("Option 1");
+		list.add("Option 2");
+
+		FileUploadField fileUpload = new FileUploadField("fileUpload", new Model<>(new ArrayList<>()));
+		fileUpload.setOutputMarkupPlaceholderTag(true);
+		form.add(fileUpload);
+
+		DropDownChoice<String> dropDown = new DropDownChoice<>("dropDown", list);
+		dropDown.add(new OnChangeAjaxBehavior() {
+
+			@Override
+			protected void onUpdate(AjaxRequestTarget target) {
+				fileUpload.setVisible(!fileUpload.isVisible());
+				target.add(fileUpload);
+
+			}
+		});
+		form.add(dropDown);
+
+		final Label label = new Label("label");
+		add(label);
+
+		form.add(new Button("submitButton") {
+			@Override
+			public void onSubmit() {
+				label.setDefaultModel(new Model<>(model.getObject().getTextField()));
+			}
+
+			@Override
+			public void onError() {
+				label.setDefaultModel(new Model<>("Validation Error..."));
+			}
+		});
+
+	}
+}
diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerTest.java
new file mode 100644
index 0000000..b5cbf26
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/MultipartFormComponentListenerTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.protocol.http;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.util.tester.TagTester;
+import org.apache.wicket.util.tester.WicketTestCase;
+import org.junit.jupiter.api.Test;
+
+/**
+ * https://issues.apache.org/jira/browse/WICKET-6914
+ */
+class MultipartFormComponentListenerTest extends WicketTestCase
+{
+    @Test
+    void updateFormEnctype()
+    {
+        tester.startPage(MultipartFormComponentListenerPage.class);
+        tester.assertRenderedPage(MultipartFormComponentListenerPage.class);
+
+        TagTester formTagTester = tester.getTagByWicketId("form");
+        assertEquals(Form.ENCTYPE_MULTIPART_FORM_DATA, formTagTester.getAttribute("enctype"));
+
+        tester.getRequest().setAttribute("form:dropDown", 1);
+        tester.executeAjaxEvent("form:dropDown", "change");
+        String ajaxResponse = tester.getLastResponseAsString();
+        assertTrue(ajaxResponse.contains(".form.enctype='" + MultipartFormComponentListener.ENCTYPE_URL_ENCODED + "'})();"));
+
+        tester.getRequest().setAttribute("form:dropDown", 2);
+        tester.executeAjaxEvent("form:dropDown", "change");
+        ajaxResponse = tester.getLastResponseAsString();
+        assertTrue(ajaxResponse.contains(".form.enctype='" + Form.ENCTYPE_MULTIPART_FORM_DATA + "'})();"));
+    }
+}