Re: Testing DropDownChoice with Ajax
I see what happens. Since DropDownChoice wants to be notified when the selection change it submits the new value as soon as formTester#select() is called. FormTester#submit() submits with empty request parameters (because the new value for the DDC is already submitted) and thus the check for required fails. You can use formTester.setValue(dropdown, 0); instead of #select(String, int) to avoid the call of #selectionChanged() callback. On Thu, Jan 17, 2013 at 3:12 AM, RalfButler ralf.but...@web.de wrote: Yes, indeed, it looks similar, except that I receive the same error messages as before if the requirement of dropdown is set to true in MockPageWithForm: dropDown.setRequired(true); and add assertNoErrorMessage to FormDispatchEventTest#dropDownEvent(): ... FormTester formTester = tester.newFormTester(form); formTester.select(dropdown, 0); formTester.submit(); // new entry which checks for any error message tester.assertNoErrorMessage(); MockPageWithForm page = (MockPageWithForm)tester.getLastRenderedPage(); ... I'm a bit puzzled why that is and would appreciate any help you can give. Thanks, Ralf -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Testing-DropDownChoice-with-Ajax-tp4655418p4655437.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 -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com http://jweekend.com/
Testing DropDownChoice with Ajax
Hi there, I'm using Wicket 6.4 and try to test a super simple form: public final class MyForm extends WebPage { public MyForm() { super(); Form form = new Form(form); TextField textField = new TextField(textfield); textField.setRequired(true); form.add(textField); DropDownChoice dropDownChoice = new DropDownChoice(dropdown, new Model(), new ArrayList(Arrays.asList(a, b, c))){ @Override protected boolean wantOnSelectionChangedNotifications() { return true; } @Override protected void onSelectionChanged(Object newSelection) { System.out.println(change); } }; dropDownChoice.setRequired(true); form.add(dropDownChoice); form.add(new SubmitLink(submitLink) { @Override public void onSubmit() { // return back to the home page setResponsePage(HomePage.class); } }); add(form); } } My test looks like this: public class TestMyForm { private WicketTester tester; @Before public void setUp() { tester = new WicketTester(new WicketApplication()); } @Test public void homepageRendersSuccessfully() { //start and render the test page tester.startPage(MyForm.class); //assert rendered page class tester.assertRenderedPage(MyForm.class); } @Test public void enterData(){ tester.startPage(MyForm.class); FormTester formTester = tester.newFormTester(form); formTester.setValue(textfield, Hello World); formTester.select(dropdown, 1); tester.executeAjaxEvent(form:dropdown, onchange); formTester.submit(); tester.assertNoErrorMessage(); tester.assertRenderedPage(HomePage.class); } } The result is: Testcase: enterData(eu.sudus.TestMyForm): FAILED expect no error message, but contains 'textfield' is required. 'dropdown' is required. I understand the textfield is less the problem, but the submitting the dropdownchoice value. Can someone help me out? Thanks, Ralf -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Testing-DropDownChoice-with-Ajax-tp4655418.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
Re: Testing DropDownChoice with Ajax
Hi, On Wed, Jan 16, 2013 at 10:02 AM, RalfButler ralf.but...@web.de wrote: Hi there, I'm using Wicket 6.4 and try to test a super simple form: public final class MyForm extends WebPage { public MyForm() { super(); Form form = new Form(form); TextField textField = new TextField(textfield); textField.setRequired(true); form.add(textField); DropDownChoice dropDownChoice = new DropDownChoice(dropdown, new Model(), new ArrayList(Arrays.asList(a, b, c))){ @Override protected boolean wantOnSelectionChangedNotifications() { return true; This uses 'onchange' inline attribute but it is *not* Ajax submit. This onchange just does this.form.submit(); } @Override protected void onSelectionChanged(Object newSelection) { System.out.println(change); } }; dropDownChoice.setRequired(true); form.add(dropDownChoice); form.add(new SubmitLink(submitLink) { @Override public void onSubmit() { // return back to the home page setResponsePage(HomePage.class); } }); add(form); } } My test looks like this: public class TestMyForm { private WicketTester tester; @Before public void setUp() { tester = new WicketTester(new WicketApplication()); } @Test public void homepageRendersSuccessfully() { //start and render the test page tester.startPage(MyForm.class); //assert rendered page class tester.assertRenderedPage(MyForm.class); } @Test public void enterData(){ tester.startPage(MyForm.class); FormTester formTester = tester.newFormTester(form); formTester.setValue(textfield, Hello World); formTester.select(dropdown, 1); tester.executeAjaxEvent(form:dropdown, onchange); There is no Ajax behavior so the above wont work. You need either to do: formTester.submit() or add AjaxFormSubmitBehavior(change) to the drop down. formTester.submit(); tester.assertNoErrorMessage(); tester.assertRenderedPage(HomePage.class); } } The result is: Testcase: enterData(eu.sudus.TestMyForm): FAILED expect no error message, but contains 'textfield' is required. 'dropdown' is required. I understand the textfield is less the problem, but the submitting the dropdownchoice value. Can someone help me out? Thanks, Ralf -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Testing-DropDownChoice-with-Ajax-tp4655418.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 -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com http://jweekend.com/
Re: Testing DropDownChoice with Ajax
Thanks a lot Martin for that super quick reply! Yes, obviously I was wrong on the AJAX part. But even if I using the test method like this: @Test public void enterData(){ tester.startPage(MyForm.class); FormTester formTester = tester.newFormTester(form); formTester.setValue(textfield, Hello World!); formTester.select(dropdown, 1); formTester.submit(); tester.assertNoErrorMessage(); tester.assertRenderedPage(HomePage.class); } ... I still receive the error. I'd really love to understand what I'm missing here. Thanks, Ralf -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Testing-DropDownChoice-with-Ajax-tp4655418p4655421.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
Re: Testing DropDownChoice with Ajax
Your test looks pretty much like org.apache.wicket.FormDispatchEventTest#dropDownEvent() in wicket-core/src/test/java FormDispatchEventTest#dropDownEvent() passes OK. On Wed, Jan 16, 2013 at 10:20 AM, RalfButler ralf.but...@web.de wrote: Thanks a lot Martin for that super quick reply! Yes, obviously I was wrong on the AJAX part. But even if I using the test method like this: @Test public void enterData(){ tester.startPage(MyForm.class); FormTester formTester = tester.newFormTester(form); formTester.setValue(textfield, Hello World!); formTester.select(dropdown, 1); formTester.submit(); tester.assertNoErrorMessage(); tester.assertRenderedPage(HomePage.class); } ... I still receive the error. I'd really love to understand what I'm missing here. Thanks, Ralf -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Testing-DropDownChoice-with-Ajax-tp4655418p4655421.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 -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com http://jweekend.com/
Re: Testing DropDownChoice with Ajax
Yes, indeed, it looks similar, except that I receive the same error messages as before if the requirement of dropdown is set to true in MockPageWithForm: dropDown.setRequired(true); and add assertNoErrorMessage to FormDispatchEventTest#dropDownEvent(): ... FormTester formTester = tester.newFormTester(form); formTester.select(dropdown, 0); formTester.submit(); // new entry which checks for any error message tester.assertNoErrorMessage(); MockPageWithForm page = (MockPageWithForm)tester.getLastRenderedPage(); ... I'm a bit puzzled why that is and would appreciate any help you can give. Thanks, Ralf -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Testing-DropDownChoice-with-Ajax-tp4655418p4655437.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
Re: test for dropdownchoice with ajax - response is homepage always
On Tue, 2009-12-01 at 08:32 +0200, Martin Makundi wrote: Hi! When I test a page like this http://www.wicket-library.com/wicket-examples/ajax/choice with wicket tester and submit the form, the response page is the HomePage instead of the expected page (ChoicePage). Do you use a formtester? The wicket tester executeajax does not properly submit the form values so what we do is we create a dummy formtester before calling executeajaxevent. That might help. Thanx for your feedback! Did you have a look at http://is.gd/58mq3 which shows the test? Yes, I'm using a formTester. What is your actual advice how to work around? I didn't get this :) Cheers, Martin ** Martin This issue was already reported some time ago without a final result: http://old.nabble.com/unit-test-for-dropdownchoice-with-ajax-td21141772.html I created an example project that shows this issue: http://github.com/magro/misc/tree/master/wicket-tester-drop-downs/ This is the short link to the failing test case (on github): http://is.gd/58mq3 This is the tested page class: http://is.gd/58mDm I'm using wicket 1.4.3. Is there any error in the test? Can I do anything to work around this, or is it a bug? Thanx cheers, Martin -- Martin Grotzke http://www.javakaffee.de/blog/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Martin Grotzke http://www.javakaffee.de/blog/ signature.asc Description: This is a digitally signed message part
Re: test for dropdownchoice with ajax - response is homepage always
Thanx for your feedback! Did you have a look at http://is.gd/58mq3 which shows the test? Ofcourse I didn't look ;) Now, having looked at it your bug is that FORMTESTER CAN BE SUBMITTED ONLY ONCE! If you want to use it another time, you need to call newFormTester again. ** Martin ** Martin This issue was already reported some time ago without a final result: http://old.nabble.com/unit-test-for-dropdownchoice-with-ajax-td21141772.html I created an example project that shows this issue: http://github.com/magro/misc/tree/master/wicket-tester-drop-downs/ This is the short link to the failing test case (on github): http://is.gd/58mq3 This is the tested page class: http://is.gd/58mDm I'm using wicket 1.4.3. Is there any error in the test? Can I do anything to work around this, or is it a bug? Thanx cheers, Martin -- Martin Grotzke http://www.javakaffee.de/blog/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Martin Grotzke http://www.javakaffee.de/blog/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: test for dropdownchoice with ajax - response is homepage always
On Tue, 2009-12-01 at 11:44 +0200, Martin Makundi wrote: Thanx for your feedback! Did you have a look at http://is.gd/58mq3 which shows the test? Ofcourse I didn't look ;) Now, having looked at it your bug is that FORMTESTER CAN BE SUBMITTED ONLY ONCE! If you want to use it another time, you need to call newFormTester again. Thanx, this fixed the issue! Now I extended the test to make sure that the previously selected make and model are still selected after the final submit - and this fails with the second drop down (the model): this returns null from dropDown.getDefaultModelObject. I pushed this, so http://is.gd/58mq3 shows these changes. Is there another thing that needs to be changed in the test? Cheers, Martin ** Martin ** Martin This issue was already reported some time ago without a final result: http://old.nabble.com/unit-test-for-dropdownchoice-with-ajax-td21141772.html I created an example project that shows this issue: http://github.com/magro/misc/tree/master/wicket-tester-drop-downs/ This is the short link to the failing test case (on github): http://is.gd/58mq3 This is the tested page class: http://is.gd/58mDm I'm using wicket 1.4.3. Is there any error in the test? Can I do anything to work around this, or is it a bug? Thanx cheers, Martin -- Martin Grotzke http://www.javakaffee.de/blog/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Martin Grotzke http://www.javakaffee.de/blog/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org signature.asc Description: This is a digitally signed message part
Re: test for dropdownchoice with ajax - response is homepage always
Line 63 you are re-using the same formTester. Cannot work. ** Martin 2009/12/1 Martin Grotzke martin.grot...@javakaffee.de: On Tue, 2009-12-01 at 11:44 +0200, Martin Makundi wrote: Thanx for your feedback! Did you have a look at http://is.gd/58mq3 which shows the test? Ofcourse I didn't look ;) Now, having looked at it your bug is that FORMTESTER CAN BE SUBMITTED ONLY ONCE! If you want to use it another time, you need to call newFormTester again. Thanx, this fixed the issue! Now I extended the test to make sure that the previously selected make and model are still selected after the final submit - and this fails with the second drop down (the model): this returns null from dropDown.getDefaultModelObject. I pushed this, so http://is.gd/58mq3 shows these changes. Is there another thing that needs to be changed in the test? Cheers, Martin ** Martin ** Martin This issue was already reported some time ago without a final result: http://old.nabble.com/unit-test-for-dropdownchoice-with-ajax-td21141772.html I created an example project that shows this issue: http://github.com/magro/misc/tree/master/wicket-tester-drop-downs/ This is the short link to the failing test case (on github): http://is.gd/58mq3 This is the tested page class: http://is.gd/58mDm I'm using wicket 1.4.3. Is there any error in the test? Can I do anything to work around this, or is it a bug? Thanx cheers, Martin -- Martin Grotzke http://www.javakaffee.de/blog/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Martin Grotzke http://www.javakaffee.de/blog/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: test for dropdownchoice with ajax - response is homepage always
On Tue, 2009-12-01 at 15:46 +0200, Martin Makundi wrote: Line 63 you are re-using the same formTester. Cannot work. Wow, really fast! :) However, I already had tested this and it doesn't make any difference - the test still fails with the same error. FWIW, I updated and pushed the test so that you can see what I actually changed. Thanx cheers, Martin ** Martin 2009/12/1 Martin Grotzke martin.grot...@javakaffee.de: On Tue, 2009-12-01 at 11:44 +0200, Martin Makundi wrote: Thanx for your feedback! Did you have a look at http://is.gd/58mq3 which shows the test? Ofcourse I didn't look ;) Now, having looked at it your bug is that FORMTESTER CAN BE SUBMITTED ONLY ONCE! If you want to use it another time, you need to call newFormTester again. Thanx, this fixed the issue! Now I extended the test to make sure that the previously selected make and model are still selected after the final submit - and this fails with the second drop down (the model): this returns null from dropDown.getDefaultModelObject. I pushed this, so http://is.gd/58mq3 shows these changes. Is there another thing that needs to be changed in the test? Cheers, Martin ** Martin ** Martin This issue was already reported some time ago without a final result: http://old.nabble.com/unit-test-for-dropdownchoice-with-ajax-td21141772.html I created an example project that shows this issue: http://github.com/magro/misc/tree/master/wicket-tester-drop-downs/ This is the short link to the failing test case (on github): http://is.gd/58mq3 This is the tested page class: http://is.gd/58mDm I'm using wicket 1.4.3. Is there any error in the test? Can I do anything to work around this, or is it a bug? Thanx cheers, Martin -- Martin Grotzke http://www.javakaffee.de/blog/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Martin Grotzke http://www.javakaffee.de/blog/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org signature.asc Description: This is a digitally signed message part
Re: test for dropdownchoice with ajax - response is homepage always
However, I already had tested this and it doesn't make any difference - the test still fails with the same error. I am not sure what you are doing. Do like this { // Operation 1 FormTester f1 = tester.newFormTester (...); f1.setValue tester.execute ... } { // Operation 2 FormTester f1 = tester.newFormTester (...); f1.setValue f1.submit } ** Martin Thanx cheers, Martin ** Martin 2009/12/1 Martin Grotzke martin.grot...@javakaffee.de: On Tue, 2009-12-01 at 11:44 +0200, Martin Makundi wrote: Thanx for your feedback! Did you have a look at http://is.gd/58mq3 which shows the test? Ofcourse I didn't look ;) Now, having looked at it your bug is that FORMTESTER CAN BE SUBMITTED ONLY ONCE! If you want to use it another time, you need to call newFormTester again. Thanx, this fixed the issue! Now I extended the test to make sure that the previously selected make and model are still selected after the final submit - and this fails with the second drop down (the model): this returns null from dropDown.getDefaultModelObject. I pushed this, so http://is.gd/58mq3 shows these changes. Is there another thing that needs to be changed in the test? Cheers, Martin ** Martin ** Martin This issue was already reported some time ago without a final result: http://old.nabble.com/unit-test-for-dropdownchoice-with-ajax-td21141772.html I created an example project that shows this issue: http://github.com/magro/misc/tree/master/wicket-tester-drop-downs/ This is the short link to the failing test case (on github): http://is.gd/58mq3 This is the tested page class: http://is.gd/58mDm I'm using wicket 1.4.3. Is there any error in the test? Can I do anything to work around this, or is it a bug? Thanx cheers, Martin -- Martin Grotzke http://www.javakaffee.de/blog/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Martin Grotzke http://www.javakaffee.de/blog/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: test for dropdownchoice with ajax - response is homepage always
Great, it's working now. I didn't use exactly the same formTester which was used for selecting the second dropdown before, that was the reason why it didn't work. Thanx for your help, cheers, Martin On Tue, 2009-12-01 at 16:03 +0200, Martin Makundi wrote: However, I already had tested this and it doesn't make any difference - the test still fails with the same error. I am not sure what you are doing. Do like this { // Operation 1 FormTester f1 = tester.newFormTester (...); f1.setValue tester.execute ... } { // Operation 2 FormTester f1 = tester.newFormTester (...); f1.setValue f1.submit } ** Martin Thanx cheers, Martin ** Martin 2009/12/1 Martin Grotzke martin.grot...@javakaffee.de: On Tue, 2009-12-01 at 11:44 +0200, Martin Makundi wrote: Thanx for your feedback! Did you have a look at http://is.gd/58mq3 which shows the test? Ofcourse I didn't look ;) Now, having looked at it your bug is that FORMTESTER CAN BE SUBMITTED ONLY ONCE! If you want to use it another time, you need to call newFormTester again. Thanx, this fixed the issue! Now I extended the test to make sure that the previously selected make and model are still selected after the final submit - and this fails with the second drop down (the model): this returns null from dropDown.getDefaultModelObject. I pushed this, so http://is.gd/58mq3 shows these changes. Is there another thing that needs to be changed in the test? Cheers, Martin ** Martin ** Martin This issue was already reported some time ago without a final result: http://old.nabble.com/unit-test-for-dropdownchoice-with-ajax-td21141772.html I created an example project that shows this issue: http://github.com/magro/misc/tree/master/wicket-tester-drop-downs/ This is the short link to the failing test case (on github): http://is.gd/58mq3 This is the tested page class: http://is.gd/58mDm I'm using wicket 1.4.3. Is there any error in the test? Can I do anything to work around this, or is it a bug? Thanx cheers, Martin -- Martin Grotzke http://www.javakaffee.de/blog/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Martin Grotzke http://www.javakaffee.de/blog/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org signature.asc Description: This is a digitally signed message part
test for dropdownchoice with ajax - response is homepage always
Hi, When I test a page like this http://www.wicket-library.com/wicket-examples/ajax/choice with wicket tester and submit the form, the response page is the HomePage instead of the expected page (ChoicePage). This issue was already reported some time ago without a final result: http://old.nabble.com/unit-test-for-dropdownchoice-with-ajax-td21141772.html I created an example project that shows this issue: http://github.com/magro/misc/tree/master/wicket-tester-drop-downs/ This is the short link to the failing test case (on github): http://is.gd/58mq3 This is the tested page class: http://is.gd/58mDm I'm using wicket 1.4.3. Is there any error in the test? Can I do anything to work around this, or is it a bug? Thanx cheers, Martin -- Martin Grotzke http://www.javakaffee.de/blog/ signature.asc Description: This is a digitally signed message part
Re: test for dropdownchoice with ajax - response is homepage always
Hi! When I test a page like this http://www.wicket-library.com/wicket-examples/ajax/choice with wicket tester and submit the form, the response page is the HomePage instead of the expected page (ChoicePage). Do you use a formtester? The wicket tester executeajax does not properly submit the form values so what we do is we create a dummy formtester before calling executeajaxevent. That might help. ** Martin This issue was already reported some time ago without a final result: http://old.nabble.com/unit-test-for-dropdownchoice-with-ajax-td21141772.html I created an example project that shows this issue: http://github.com/magro/misc/tree/master/wicket-tester-drop-downs/ This is the short link to the failing test case (on github): http://is.gd/58mq3 This is the tested page class: http://is.gd/58mDm I'm using wicket 1.4.3. Is there any error in the test? Can I do anything to work around this, or is it a bug? Thanx cheers, Martin -- Martin Grotzke http://www.javakaffee.de/blog/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
DropDownChoice and AJAX
Hallo, I have a little problem with updating a DropDownChoice in a separate panel with information coming from a modal window. The new value is not updated in the DropDownChoice, only new choice is displayed when I come back from the modal window. Can you help me on this issue? Thanks, Peter P.S.: Here is the code of of a short example, in real life I would like to use objects from a database ... TestAppl.java public class TestAppl extends WebApplication { @Override public ClassTest getHomePage() { return Test.class; } } Test.html !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd; html head meta http-equiv=Content-Type content=text/html; charset=ISO-8859-1 titleWicket Test/title /head body span wicket:id=textLabel1/span form wicket:id=testForm div wicket:id=namePanel/div /form div id=feedbackPanel span wicket:id=feedback/span /div /body /html Test.java public class Test extends WebPage { public Test() { add(new Label(textLabel1,WicketTest - DropDownChoice)); Form testForm = new Form(testForm); add(testForm); testForm.add(new NamePanel(namePanel)); add(new FeedbackPanel(feedback)); } } NamePanel.html wicket:panel select wicket:id=nameSelect optionPeter/option /select div style=position:absolute;top:100px;left=20px;width:200px;height:50px; wicket:id=modalNameInput/div a href=# wicket:id=newnew/a /wicket:panel NamePanel.java public class NamePanel extends Panel { private static final long serialVersionUID = 1L; private static final Log log = LogFactory.getLog(NamePanel.class); private ArrayListString names = new ArrayListString(Arrays.asList (Peter,Stephan)); private String selName = Peter; public NamePanel(String id) { super(id); final DropDownChoice ddc = new DropDownChoice(nameSelect, new Model(selName), names);); ddc.setOutputMarkupId(true); add(ddc); final ModalWindow modalInput; add(modalInput = new ModalWindow(modalNameInput)); modalInput.setContent(new ModalNameInputPanel (modalInput.getContentId(),modalInput,NamePanel.this)); modalInput.setTitle(Neuer Name ...); modalInput.setInitialWidth(200);... modalInput.setInitialHeight(100);); modalInput.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { private static final long serialVersionUID = 1L; public boolean onCloseButtonClicked(AjaxRequestTarget target) { log.debug(CloseButton: + selName); return true; } }); modalInput.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = 1L; public void onClose(AjaxRequestTarget target) { target.addComponent(ddc); log.debug(CloseCallback: + selName); } }); add(new AjaxLink(new) { private static final long serialVersionUID = 1L; public void onClick(AjaxRequestTarget target) { modalInput.show(target); } }); } public void setSelName(String selName) { this.selName = selName; } } ModalNameInputPanel.html wicket:panel div form wicket:id=nameForm label for=nameName:/label input id=name wicket:id=nameIn type=text /br/. input type=submit wicket:id=ok value=ok/ input type=reset wicket:id=cancel value=cancel/. /form /div /wicket:panel ModalNameInputPanel.java public class ModalNameInputPanel extends Panel { private static final long serialVersionUID = 1L; private static final Log log = LogFactory.getLog (ModalNameInputPanel.class); private ModalWindow window; private NamePanel namePanel; private String nameIn = Knut; public ModalNameInputPanel(String id, final ModalWindow win, NamePanel np) { super(id); this.window = win; this.namePanel = np; PropertyModel nameModel = new PropertyModel(this, nameIn); Form nameForm = new Form(nameForm); add(nameForm); nameForm.add(new TextField(nameIn,nameModel));, nameForm.add(new NameSubmitLink(ok,true)); nameForm.add(new NameSubmitLink(cancel,false)); } private class NameSubmitLink extends AjaxSubmitLink { private static final long serialVersionUID = 1L; private boolean save = false; public NameSubmitLink(String id,boolean save) {; super(id);
Re: unit test for dropdownchoice with ajax
On Tue, 23 Dec 2008, tbt wrote: formTester.submit(); If you submit the form with Ajax, you should use WicketTester.executeAjaxEvent in the test instead. Anyway, it seems like there might be a bug. If you can debug some more and/or produce a quickstart that reproduces the problem, it would be good. Otherwise it's difficult to say what's the problem. Best wishes, Timo -- Timo Rantalaiho Reaktor Innovations OyURL: http://www.ri.fi/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: unit test for dropdownchoice with ajax
I am having the same issue with multiple drop downs with ajax, when trying to unit test. tbt wrote: Hi I have coded two dropdown boxes similar to the example provided at http://http://www.wicket-library.com/wicket-examples/ajax/choice.1 The hotel dropdown is populated once a country is selected via ajax. This works fine and now i am writing a unit test for it. The code is as follows WicketTester wicketTester = getWicketTester(); wicketTester.startPage(SearchHotelsPage.class); FormTester formTester = wicketTester.newFormTester(searchHotelsForm,false); formTester.select(countryDropDown, 6); DropDownChoice countryDropDownChoice = (DropDownChoice) wicketTester.getComponentFromLastRenderedPage(searchHotelsForm:countryDropDown); assertEquals(countryDropDownChoice.getChoices().size(), 41); wicketTester.executeAjaxEvent(searchHotelsForm:countryDropDown, onchange); wicketTester.assertComponentOnAjaxResponse(searchHotelsForm:hotelDropDown); formTester.select(hotelDropDown, 12); formTester.submit(); wicketTester.assertRenderedPage(EditHotelsPage.class); but the following line fails the unit test wicketTester.assertRenderedPage(EditHotelsPage.class); the stack trace is as follows junit.framework.AssertionFailedError: expected:EditHotelsPage but was:HomePage at org.apache.wicket.util.tester.WicketTester.assertResult(WicketTester.java:575) at org.apache.wicket.util.tester.WicketTester.assertRenderedPage(WicketTester.java:522) at ogn.forms.SearchHotelsFormTest.testAjaxDropdownComponent(SearchHotelsFormTest.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at junit.framework.TestCase.runTest(TestCase.java:164) at junit.framework.TestCase.runBare(TestCase.java:130) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:120) at junit.framework.TestSuite.runTest(TestSuite.java:230) at junit.framework.TestSuite.run(TestSuite.java:225) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Why does the page get rendered to the HomePage when the form is submitted. Am I testing the ajax dropdown component correctly. Please help. Thanks -- View this message in context: http://www.nabble.com/unit-test-for-dropdownchoice-with-ajax-tp21141772p21509601.html Sent from the Wicket - User 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
unit test for dropdownchoice with ajax
Hi I have coded two dropdown boxes similar to the example provided at http://http://www.wicket-library.com/wicket-examples/ajax/choice.1 The hotel dropdown is populated once a country is selected via ajax. This works fine and now i am writing a unit test for it. The code is as follows WicketTester wicketTester = getWicketTester(); wicketTester.startPage(SearchHotelsPage.class); FormTester formTester = wicketTester.newFormTester(searchHotelsForm,false); formTester.select(countryDropDown, 6); DropDownChoice countryDropDownChoice = (DropDownChoice) wicketTester.getComponentFromLastRenderedPage(searchHotelsForm:countryDropDown); assertEquals(countryDropDownChoice.getChoices().size(), 41); wicketTester.executeAjaxEvent(searchHotelsForm:countryDropDown, onchange); wicketTester.assertComponentOnAjaxResponse(searchHotelsForm:hotelDropDown); formTester.select(hotelDropDown, 12); formTester.submit(); wicketTester.assertRenderedPage(EditHotelsPage.class); but the following line fails the unit test wicketTester.assertRenderedPage(EditHotelsPage.class); the stack trace is as follows junit.framework.AssertionFailedError: expected:EditHotelsPage but was:HomePage at org.apache.wicket.util.tester.WicketTester.assertResult(WicketTester.java:575) at org.apache.wicket.util.tester.WicketTester.assertRenderedPage(WicketTester.java:522) at ogn.forms.SearchHotelsFormTest.testAjaxDropdownComponent(SearchHotelsFormTest.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at junit.framework.TestCase.runTest(TestCase.java:164) at junit.framework.TestCase.runBare(TestCase.java:130) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:120) at junit.framework.TestSuite.runTest(TestSuite.java:230) at junit.framework.TestSuite.run(TestSuite.java:225) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Why does the page get rendered to the HomePage when the form is submitted. Am I testing the ajax dropdown component correctly. Please help. Thanks -- View this message in context: http://www.nabble.com/unit-test-for-dropdownchoice-with-ajax-tp21141772p21141772.html Sent from the Wicket - User 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
Re: DropDownChoice setting other DropDownChoice using AJAX results in null at submit
())); target.addComponent(chosenArmy); } }); } class StwPrefForm extends BaseForm { public StwPrefForm(String id) { super(id); } @Override public void onSubmit() { System.out.println(stwMatchPrefs.getMapCategory() = + stwMatchPrefs.getMapCategory()); System.out.println(stwMatchPrefs.getChosenArmy() = + stwMatchPrefs.getChosenArmy()); } } } - Original Message From: Timo Rantalaiho [EMAIL PROTECTED] To: users@wicket.apache.org Sent: Tuesday, June 24, 2008 12:27:42 AM Subject: Re: DropDownChoice setting other DropDownChoice using AJAX results in null at submit On Mon, 23 Jun 2008, Giuliano Caliari wrote: When the user sets the value on the first DDC, the value of the second DDC is set without problems, even the selected value is set correctly. The problem is that if the user changes the value on the first DDC (mapCategory) and then submits, the value passed on the second DDC (chosenArmy) is always null, so the value received by stwMatchPrefs is null. Hi, I haven't completely understood what is happening here, but will try to give some ideas below. There is something strange happening with the models there. Have you read the models wiki page? You could also try removing PropertyModel and CompoundPropertyModel usage for now, because they might obfuscate the problem. IModel armyChoices = new AbstractReadOnlyModel() { public Object getObject() { ListArmy armys = new ArrayListArmy(); armys.add(stwData.getArmyByCategory(StwMapCategory.SMALL)); armys.add(stwData.getArmyByCategory(StwMapCategory.MEDIUM)); armys.add(stwData.getArmyByCategory(StwMapCategory.LARGE)); stwMatchPrefs.setChosenArmy(stwData.getArmyByCategory(stwMatchPrefs.getMapCategory())); return armys; } }; This seems like a strange side effect -- whenever a component with armyChoices as its model is rendered, stwMatchPrefs.setChosenArmy() is called. Because this is the model of the chosenArmy DropDownChoice, whenever the DropDownChoice is rendered, this getObject() method is evaluated. But then again final DropDownChoice chosenArmy = new DropDownChoice(chosenArmy, new PropertyModel(stwMatchPrefs, chosenArmy), armyChoices, armyChoicesRenderer ); chosenArmy.setOutputMarkupId(true); stwPrefsForm.add(chosenArmy); mapCategory.add(new AjaxFormComponentUpdatingBehavior(onchange) { protected void onUpdate(AjaxRequestTarget target) { stwMatchPrefs.setChosenArmy(stwData.getArmyByCategory(stwMatchPrefs.getMapCategory())); chosenArmy.setModelObject(stwMatchPrefs.getChosenArmy()); target.addComponent(chosenArmy); } }); } Here you give a PropertyModel to chosenArmy DropDownChoice, and it operates directly with the chosenArmy property of stwMatchPrefs. This means that the chosenArmy DropDownChoice selection and stwMatchPrefs.chosenArmy property are bound to each other: when one changes, the other one changes as well. In this light, it is absurd that you change both values in the onUpdate method. stwMatchPrefs.setChosenArmy() should be enough. What is even stranger is that because of the armyChoices model, stwMatchPres.setChosenArmy() is getting a competing call during rendering :) public ArmyServices getArmyServices() { return armyServices; } public void setArmyServices(ArmyServices armyServices) { this.armyServices = armyServices; } BTW, what are these methods here for? Best wishes, Timo -- Timo Rantalaiho Reaktor Innovations OyURL: http://www.ri.fi/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DropDownChoice setting other DropDownChoice using AJAX results in null at submit
On Tue, 24 Jun 2008, Giuliano Caliari wrote: As you can see I am new to wicket and I'm trying to evaluate it for my projects. Then it's a good idea to checkout the code of wicket-examples of 1.3 http://svn.apache.org/repos/asf/wicket/branches/wicket-1.3.x/jdk-1.5/wicket-examples/ alongside your project, and look at the linked DropDownChoices example http://www.wicketstuff.org/wicket13/ajax/choice.0 from there. Sure it's handy to see the live examples but it's a lot better to browse the source code in your own IDE, and you can start the examples there as well. You can then start by modding the example to do something like what you want. Also, be sure to have Wicket source code attached to your IDE. BTW, what are these methods here for? These 2 are there for spring to inject the bean @SpringBean(name=armyServices) @SpringBean works standalone, there's no need to provide a setter for your the bean dependency: http://cwiki.apache.org/WICKET/spring.html#Spring-AnnotationbasedApproach The real problem is that whenever chosenArmy DropDownChoice is changed through the AJAX code, stwMatchPrefs.setChosenArmy receives null when the form is submitted. Unfortunately I still cannot pinpoint the exact problem. Removing the PropertyModel and doing the interaction more via specified models might make the problem more apparent. Good luck :) Best wishes, Timo -- Timo Rantalaiho Reaktor Innovations OyURL: http://www.ri.fi/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
DropDownChoice setting other DropDownChoice using AJAX results in null at submit
Hello, I have a page in which there are 2 DropDownChoices. Both have to be set with an initial value. The first DDC called mapCategory is populated from a simple List. The second DDC, chosenArmy is populated by a List of objects (Army) that can change, based on the value of the first DDC and other options. I used AJAX to change the value of the second DDC based on the first DDC. In addition, the default value of the second DDC is also set when the user selects the value of the first DDC. stwMatchPrefs is the property model set to the form. When the user sets the value on the first DDC, the value of the second DDC is set without problems, even the selected value is set correctly. The problem is that if the user changes the value on the first DDC (mapCategory) and then submits, the value passed on the second DDC (chosenArmy) is always null, so the value received by stwMatchPrefs is null. If the user submits without changing the value on the first DDC, everything work and the value of stwMatchPrefs is set correctly. If the user changes the value on the first DDC (mapCategory) and then submits twice, the first time the value of chosenArmy is null, but the second submit has the right value. Can anyone help me? Thanks in advance. Here's the page, with both DDC I'm using wicket 1.3.3. Lines 57-65 have the AJAX code. public class StwFrontPage extends BasePage { @SpringBean(name=armyServices) private ArmyServices armyServices; StwData stwData; StwMatchPrefs stwMatchPrefs; public StwFrontPage() { stwMatchPrefs = new StwMatchPrefs(); CompoundPropertyModel userProfileModel = new CompoundPropertyModel(stwMatchPrefs); Form stwPrefsForm = new StwPrefForm(StwPrefsForm,userProfileModel); add(stwPrefsForm); stwMatchPrefs.setMapCategory(StwMapCategory.SMALL); DropDownChoice mapCategory = new DropDownChoice(mapCategory, new PropertyModel(stwMatchPrefs, mapCategory), StwMapCategory.getList()); stwPrefsForm.add(mapCategory); IChoiceRenderer armyChoicesRenderer = new IChoiceRenderer() { public Object getDisplayValue(Object o) { return ((Army)o).getName(); } public String getIdValue(Object o, int i) { return Integer.toString(i); } }; stwData = AbismoWicketWebSession.get().getNewAbismoUser().getStwData(); if(stwData == null){ stwData = new StwData(); } if(!stwData.isInitialized()){ stwData.init(AbismoWicketWebSession.get().getNewAbismoUser(), armyServices.getBasicArmy(StwMapCategory.SMALL), armyServices.getBasicArmy(StwMapCategory.MEDIUM), armyServices.getBasicArmy(StwMapCategory.LARGE) ); } IModel armyChoices = new AbstractReadOnlyModel() { public Object getObject() { List Army armys = new ArrayList Army (); armys.add(stwData.getArmyByCategory(StwMapCategory.SMALL)); armys.add(stwData.getArmyByCategory(StwMapCategory.MEDIUM)); armys.add(stwData.getArmyByCategory(StwMapCategory.LARGE)); stwMatchPrefs.setChosenArmy(stwData.getArmyByCategory(stwMatchPrefs.getMapCategory())); return armys; } }; final DropDownChoice chosenArmy = new DropDownChoice(chosenArmy, new PropertyModel(stwMatchPrefs, chosenArmy), armyChoices, armyChoicesRenderer ); chosenArmy.setOutputMarkupId(true); stwPrefsForm.add(chosenArmy); mapCategory.add(new AjaxFormComponentUpdatingBehavior(onchange) { protected void onUpdate(AjaxRequestTarget target) { stwMatchPrefs.setChosenArmy(stwData.getArmyByCategory(stwMatchPrefs.getMapCategory())); chosenArmy.setModelObject(stwMatchPrefs.getChosenArmy()); target.addComponent(chosenArmy); } }); } public ArmyServices getArmyServices() { return armyServices; } public void setArmyServices(ArmyServices armyServices) { this.armyServices = armyServices; } class StwPrefForm extends BaseForm { // PropertyModel is an IModel implementation public StwPrefForm(String id, IModel model) { super(id, model); } @Override public void onSubmit() { StwMatchPrefs stwMatchPrefs = (StwMatchPrefs)getModelObject(); System.out.println(stwMatchPrefs.getMapCategory() = + stwMatchPrefs.getMapCategory()); System.out.println(stwMatchPrefs.getChosenArmy() = + stwMatchPrefs.getChosenArmy()); } } } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DropDownChoice setting other DropDownChoice using AJAX results in null at submit
On Mon, 23 Jun 2008, Giuliano Caliari wrote: When the user sets the value on the first DDC, the value of the second DDC is set without problems, even the selected value is set correctly. The problem is that if the user changes the value on the first DDC (mapCategory) and then submits, the value passed on the second DDC (chosenArmy) is always null, so the value received by stwMatchPrefs is null. Hi, I haven't completely understood what is happening here, but will try to give some ideas below. There is something strange happening with the models there. Have you read the models wiki page? You could also try removing PropertyModel and CompoundPropertyModel usage for now, because they might obfuscate the problem. IModel armyChoices = new AbstractReadOnlyModel() { public Object getObject() { ListArmy armys = new ArrayListArmy(); armys.add(stwData.getArmyByCategory(StwMapCategory.SMALL)); armys.add(stwData.getArmyByCategory(StwMapCategory.MEDIUM)); armys.add(stwData.getArmyByCategory(StwMapCategory.LARGE)); stwMatchPrefs.setChosenArmy(stwData.getArmyByCategory(stwMatchPrefs.getMapCategory())); return armys; } }; This seems like a strange side effect -- whenever a component with armyChoices as its model is rendered, stwMatchPrefs.setChosenArmy() is called. Because this is the model of the chosenArmy DropDownChoice, whenever the DropDownChoice is rendered, this getObject() method is evaluated. But then again final DropDownChoice chosenArmy = new DropDownChoice(chosenArmy, new PropertyModel(stwMatchPrefs, chosenArmy), armyChoices, armyChoicesRenderer ); chosenArmy.setOutputMarkupId(true); stwPrefsForm.add(chosenArmy); mapCategory.add(new AjaxFormComponentUpdatingBehavior(onchange) { protected void onUpdate(AjaxRequestTarget target) { stwMatchPrefs.setChosenArmy(stwData.getArmyByCategory(stwMatchPrefs.getMapCategory())); chosenArmy.setModelObject(stwMatchPrefs.getChosenArmy()); target.addComponent(chosenArmy); } }); } Here you give a PropertyModel to chosenArmy DropDownChoice, and it operates directly with the chosenArmy property of stwMatchPrefs. This means that the chosenArmy DropDownChoice selection and stwMatchPrefs.chosenArmy property are bound to each other: when one changes, the other one changes as well. In this light, it is absurd that you change both values in the onUpdate method. stwMatchPrefs.setChosenArmy() should be enough. What is even stranger is that because of the armyChoices model, stwMatchPres.setChosenArmy() is getting a competing call during rendering :) public ArmyServices getArmyServices() { return armyServices; } public void setArmyServices(ArmyServices armyServices) { this.armyServices = armyServices; } BTW, what are these methods here for? Best wishes, Timo -- Timo Rantalaiho Reaktor Innovations OyURL: http://www.ri.fi/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Unit testing - updating a DropDownChoice with Ajax : follow on from old mailing list
I managed to solve it by setting the values directly using: tester.setParameterForNextRequest(wizard:form:view:phoneMaker, 1); and completely bypassing the ajax. sorry for the trouble. Simon On 17/08/07, wicket user [EMAIL PROTECTED] wrote: I'm not entirely sure that this isn't bad mailing list form but this article in the old mailing list was so close to my existing problem that I thought that I would continue it: Ok, so I've got the first part of updating a DropDownChoice Ajax unit test working as described in the forum ( http://www.nabble.com/Unit-testing---updating-a-DropDownChoice-with-Ajax-tf3946499.html) previously but when I try to * select* the second DropDownChoice and submit the form I'm getting the form returning that the value is missing. It is a required field so its supposed to object if it isn't set but I'm not sure why it's not picking up that I've set it. Here is a bit of the code: FormTester ftester = tester.newFormTester(wizard:form); // select the phone maker ftester.select(view:phone.make, 0); tester.executeAjaxEvent(PHONEMAKE, onchange); // select the phone model DropDownChoice phoneModels = (DropDownChoice)tester.getLastRenderedPage().get(PHONEMODEL); // This passes assertEquals(20, phoneModels.getChoices().size()); // Here I'm selecting the second dropdown, as usual right? ftester.select(view:phone.model, 0); // submit the wizard to the next ftester.submit(buttons:next); tester.assertNoInfoMessage(); *// Here is where I'm expecting nothing but get the missing required field* tester.assertNoErrorMessage(); I've tried various combinations of the above but to no avail. Thanks Simon