Thorsten Wendelmuth created WICKET-6951:
-------------------------------------------
Summary: WicketTester loses formInput of sibiling-forms if nested
form is submitted
Key: WICKET-6951
URL: https://issues.apache.org/jira/browse/WICKET-6951
Project: Wicket
Issue Type: Bug
Affects Versions: 9.7.0, 8.13.0
Reporter: Thorsten Wendelmuth
Attachments: NestedFormPage.html, NestedFormPage.java
In the following scenario:
{code:java}
parentForm
-> sibilingForm1
-> sibilingForm2 {code}
If you're submitting silblingForm1 with a WicketTester, sibilingForm2 will lose
the formInput state since it's part is not getting serialized to the request
(I'd assume). I tested this on Wicket 8.13.0 & 9.7.0 both with the same
results. The FormComponents on both sibilingForms where DropDownChoices - not
sure if this makes a difference.
TestCase:
{code:java}
@Test
public void test() {
//start and render the test page
NestedFormPage page = tester.startPage(NestedFormPage.class);
assertEquals("TEST", page.getDropdown1().getModelObject());
assertEquals("TEST", page.getDropdown2().getModelObject());
tester.clickLink(page.getSubmitForm1());
assertEquals("TEST", page.getDropdown1().getModelObject());
assertEquals("TEST", page.getDropdown2().getModelObject());
assertEquals(List.of("0"),
List.of(FormTester.getInputValue(page.getDropdown1())));
// real browser would send all children of the root form, but
this is actually empty
// assertEquals(List.of("0"),
List.of(FormTester.getInputValue(page.getDropdown2())));
tester.clickLink(page.getParentSubmit());
assertEquals("TEST", page.getDropdown1().getModelObject());
assertEquals("TEST", page.getDropdown2().getModelObject());
}
{code}
Also uploaded the RAW java & html class files, but here as code to demonstrate
the problem a bit more:
NestedFormPage.java
{code:java}
package org.example;
import java.util.List;
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.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.Model;
public class NestedFormPage extends WebPage {
private DropDownChoice<String> dropdown1;
private DropDownChoice<String> dropdown2;
private AjaxSubmitLink parentSubmit;
private AjaxSubmitLink submitForm1;
private AjaxSubmitLink submitForm2;
@Override
protected void onInitialize() {
super.onInitialize();
var parentForm = new Form<>("parentForm");
parentForm.setOutputMarkupId(true);
add(parentForm);
parentSubmit = new AjaxSubmitLink("parentSubmit", parentForm) {
};
parentForm.add(parentSubmit);
var form1 = new Form<>("form1");
parentForm.add(form1);
dropdown1 = new DropDownChoice<>("dropdown1", Model.of("TEST"),
List.of("TEST", "TEST2"));
form1.add(dropdown1);
submitForm1 = new AjaxSubmitLink("submit1", form1) {
@Override
protected void onSubmit(AjaxRequestTarget target) {
super.onSubmit(target);
target.add(parentForm);
}
};
form1.add(submitForm1);
var form2 = new Form<>("form2");
parentForm.add(form2);
dropdown2 = new DropDownChoice<>("dropdown2", Model.of("TEST"),
List.of("TEST", "TEST2"));
form2.add(dropdown2);
submitForm2 = new AjaxSubmitLink("submit2", form2) {
@Override
protected void onSubmit(AjaxRequestTarget target) {
super.onSubmit(target);
target.add(parentForm);
}
};
form2.add(submitForm2);
}
public DropDownChoice<String> getDropdown1() {
return dropdown1;
}
public DropDownChoice<String> getDropdown2() {
return dropdown2;
}
public AjaxSubmitLink getSubmitForm1() {
return submitForm1;
}
public AjaxSubmitLink getSubmitForm2() {
return submitForm2;
}
public AjaxSubmitLink getParentSubmit() {
return parentSubmit;
}
}
{code}
NestedFormPage.html
{code:java}
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<body>
<form wicket:id="parentForm">
<a wicket:id="parentSubmit">Parent Submit</a>
<form wicket:id="form1">
<select wicket:id="dropdown1" />
<a wicket:id="submit1">Submit</a>
</form>
<form wicket:id="form2">
<select wicket:id="dropdown2" />
<a wicket:id="submit2">Submit</a>
</form>
</form>
</body>
</html>
{code}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)