Stefan Bauer created WICKET-7160: ------------------------------------ Summary: WicketTester: onchange AJAX behavior broken for DropDownChoice when page has a request parameter with the same name as the id of the DropDownChoice Key: WICKET-7160 URL: https://issues.apache.org/jira/browse/WICKET-7160 Project: Wicket Issue Type: Bug Affects Versions: 9.21.0 Reporter: Stefan Bauer Attachments: bug.zip
h5. Steps to reproduce (see code example below) * in a Page that was instantiated using request parameters... * have a DropDownChoice whose Wicket ID is identical to the name of one of the request paameters... * add a AJAX onchange behavior... * and then try to trigger this behavior using the WicketTester h5. Expected Result (see code example below) * onchange behavior is triggered with the correct value h4. Actual Result * onchange behavior is triggered, but the value is null h4. Code example (Full source attached) {code:java} public class DemoPage extends WebPage { public DemoPage(PageParameters parameters) { super(parameters); } @Override protected void onInitialize() { super.onInitialize(); Form<String> form = new Form<>("form"); DropDownChoice<String> select = new DropDownChoice<>( "select", new Model<>(), List.of("Choice 1", "Choice 2")); select.add(OnChangeAjaxBehavior.onChange(target -> { System.out.println("Selected choice changed to: " + select.getModelObject()); })); form.add(select); add(form); } } {code} {code:java} public class DemoPageTest { @ParameterizedTest @ValueSource(strings = { "select", "somethingElse" }) void testOnChangeAjaxBehavior(String requestParameterName) { // ARRANGE WicketTester tester = new WicketTester(); tester.startPage(DemoPage.class, new PageParameters().add(requestParameterName, "23")); // ACT FormTester formTester = tester.newFormTester("form"); formTester.select("select", 1); tester.executeAjaxEvent("form:select", "change"); // ASSERT tester.assertModelValue("form:select", "Choice 2"); } } {code} h4. Background This does not happen when the page is acutally run on a real servlet container, e.g. Jetty. As far as I can see, this is related to the POST request that the WicketTester creates for triggering the onchange AJAX behavior. Given the Wicket ID of the DropDownChoice is "select", in production, the request looks something like this: URL: /page?1-1.0-form-select&select=23 Body: select=1 But in WicketTester, the request looks like this (if I debugged this correctly) URL: /page?1-1.0-form-select&select=23&select=1 Body: (empty) -- This message was sent by Atlassian Jira (v8.20.10#820010)