Hi,
On Fri, Jan 3, 2014 at 6:15 PM, Kev <kevin.se...@intesens.com> wrote: > Hi, > > I have a form with a text field and a dropdownchoice with the > OnSelectionChangedNotification enabled. When I try to test this form with a > formTester, the method seems to reset the text field value. There is not > this behavior when I start the app normally. > Is it a bug, or is it my test who is wrong ? > > *my page: * > public class FooPage extends WebPage { > private static final long serialVersionUID = 1L; > > private MyForm form; > > public FooPage() { > this.form = new MyForm("form"); > add(this.form); > } > > public String getFormValue() { > return this.form.getValue(); > } > > @SuppressWarnings({ "serial", "rawtypes" }) > public class MyForm extends Form { > > private String value; > > private TextField<String> textField = new > TextField<String>("textField", > new PropertyModel<String>(this, "value")); > > private DropDownChoice<String> dropDownChoice = new > DropDownChoice<String>( > "dropDownChoice", new Model<String>(), new > ArrayList<String>()) { > @Override > protected boolean wantOnSelectionChangedNotifications() { > > return true; > }; > > @Override > protected void onSelectionChanged(final String newSelection) { > // Something > This is essential to your question, no? ^^ What do you do here ? > }; > }; > > public MyForm(final String id) { > super(id); > > List<String> choices = new ArrayList<String>(); > choices.add("Foo"); > choices.add("Bar"); > this.dropDownChoice.setChoices(choices); > > add(this.textField); > add(this.dropDownChoice); > } > > public String getValue() { > return this.value; > } > > public void setValue(final String value) { > this.value = value; > } > } > } > > <html> > <body> > <form wicket:id="form"> > <input wicket:id="textField" type="text"/> > <select wicket:id="dropDownChoice"></select> > </form> > </body> > </html> > > *my test:* > public class FooPageTest { > private WicketTester tester = new WicketTester(); > > @Test > public void testWithoutSelect() { > FooPage page = this.tester.startPage(FooPage.class); > FormTester formTester = this.tester.newFormTester("form"); > > formTester.setValue("textField", "FOO"); > formTester.submit(); > > assertEquals("FOO", page.getFormValue()); // it's ok > } > > @Test > public void testWithSelect() { > FooPage page = this.tester.startPage(FooPage.class); > FormTester formTester = this.tester.newFormTester("form"); > > formTester.setValue("textField", "FOO"); > formTester.select("dropDownChoice", 0); // ony add this select > formTester.submit(); > > assertEquals("FOO", page.getFormValue()); // it's NOT ok > } > } > > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/Problem-with-FormTester-and-selection-on-dropDownChoice-tp4663439.html > Sent from the Users forum mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >