The Fourth Secret About Wicket

The problem

In a page we have two DropDownChoice components.
When you choose an option in the first dropdown, the second one is updated using Ajax. Is that clear? I hope it is…

Anyway, this is the part of a test that didn't work:

...
    FormTester formTester = tester.newFormTester("panel:detailsForm");
    formTester.select("braccio.corsia.codice", 1);

    formTester.select("braccio.numero", 0);
    formTester.setValue("numero", "1");
    formTester.setValue("matricola", "matr");

    formTester.submit("save");
...

Where braccio.corsia.codice and braccio.numero are the ids of the dropdown components.
Why didn't that work?

Because when you select a choice in the first dropdown, no ajax update event is sent, so the second dropdown doesn't update its data.

So folks, here's the secret

DropDownChoice dropDownChoice = (DropDownChoice) formTester.getForm().get("braccio.corsia.codice");
dropDownChoice.onSelectionChanged();

In this way, the component does exactly what it is supposed to do.

The First Three Secrets About Wicket Translated

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License