Re: WicketTester -- No Form onSubmit when using Ajax DropDownChoice Component
OK, I think I get it now Martin: -- WicketTester tester = new WicketTester(webapp); tester.setupRequestAndResponse(); FormTester formTester4Ajax = tester.newFormTester("mainPanel:officeSelectorForm"); formTester4Ajax.select("brands", 0); tester.executeAjaxEvent("mainPanel:officeSelectorForm:brands", "onchange"); tester.assertComponentOnAjaxResponse("mainPanel:officeSelectorForm:categories"); formTester4Ajax.select("categories", 0); tester.executeAjaxEvent("mainPanel:officeSelectorForm:categories", "onchange"); tester.assertComponentOnAjaxResponse("mainPanel:officeSelectorForm:titles"); FormTester formTester4Submit = tester.newFormTester("mainPanel:officeSelectorForm"); formTester4Submit.select("brands", 0); formTester4Submit.select("categories", 0); formTester4Submit.select("titles", 0); formTester4Submit.submit(); -- Not quite sure why it works but it does. Thanks very much =) -- View this message in context: http://old.nabble.com/WicketTesterNo-Form-onSubmit-when-using-Ajax-DropDownChoice-Component-tp27006022p27022783.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: WicketTester -- No Form onSubmit when using Ajax DropDownChoice Component
I am confused by something here. I am using the calls to tester.executeAjaxEvent() in order to populate the DropDownChoice components with items (these items are provided by a mocked service layer). Then I call formTester.select() in order to pick from the items provided by the tester.executeAjaxEvent() calls. These selected items are then used with the call to formTester.submit(). Are you saying that tester.executeAjaxEvent() and formTester.select() cannot be used together? If so then what would be the best way to supply the DropDownChoice items in order to properly call formTester.submit()? Thanks! -- View this message in context: http://old.nabble.com/WicketTesterNo-Form-onSubmit-when-using-Ajax-DropDownChoice-Component-tp27006022p27018255.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: WicketTester -- No Form onSubmit when using Ajax DropDownChoice Component
Ah.. then the answer is: formtester can be used only for single submit. For a new one, make a new one. It would be nice if it threw an exception (maybe create jira issue for that?). http://old.nabble.com/test-for-dropdownchoice-with-ajax---response-is-homepage-always-td26584582.html ** Martin 2010/1/4 shetc : > > Hi Martin, > > Thanks for the quick reply. The onSubmit method of my form does actually > work with the 3 linked > DropDownChoice components, when used as part of my application. I am trying > to simulate this > functionality as part of an integration test, and that's when the onSubmit > method is not triggered. > So I assume it's some misunderstanding on my part as far as WicketTester is > concerned, not > about using AjaxFormComponentUpdatingBehavior for components within a form. > > Steve > -- > View this message in context: > http://old.nabble.com/WicketTesterNo-Form-onSubmit-when-using-Ajax-DropDownChoice-Component-tp27006022p27012451.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 > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: WicketTester -- No Form onSubmit when using Ajax DropDownChoice Component
Hi Martin, Thanks for the quick reply. The onSubmit method of my form does actually work with the 3 linked DropDownChoice components, when used as part of my application. I am trying to simulate this functionality as part of an integration test, and that's when the onSubmit method is not triggered. So I assume it's some misunderstanding on my part as far as WicketTester is concerned, not about using AjaxFormComponentUpdatingBehavior for components within a form. Steve -- View this message in context: http://old.nabble.com/WicketTester----No-Form-onSubmit-when-using-Ajax-DropDownChoice-Component-tp27006022p27012451.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: WicketTester -- No Form onSubmit when using Ajax DropDownChoice Component
Hi! AjaxFormComponentUpdatingBehavior does not submit the other form values, only the involved component. If you want to handle other form values you will need something like AjaxFormSubmitBehavior or AjaxFormSubmittingChangeListenerBehavior: public abstract class AjaxFormSubmittingChangeListenerBehavior extends AjaxFormSubmitBehavior { private final static Method hiddenFieldGetter; static { try { hiddenFieldGetter = Form.class.getDeclaredMethod("getHiddenFieldId"); hiddenFieldGetter.setAccessible(true); } catch (Exception e) { throw new RuntimeException(e); } } /** * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#onBind() */ @Override protected void onBind() { super.onBind(); if (!(getComponent() instanceof IOnChangeListener)) { throw new WicketRuntimeException("Behavior " + getClass().getName() + " can only be added to an instance of a IOnChangeListener"); } } /** * @param event */ public AjaxFormSubmittingChangeListenerBehavior(String event) { super(event); } /** * @see org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onError(org.apache.wicket.ajax.AjaxRequestTarget) */ @Override protected void onError(AjaxRequestTarget target) { onSubmit(target); } /** * @see org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onEvent(org.apache.wicket.ajax.AjaxRequestTarget) */ @Override protected void onEvent(AjaxRequestTarget target) { HttpServletRequest httpServletRequest = ((WebRequest) getComponent() .getRequest()).getHttpServletRequest(); Map parameters; if (httpServletRequest instanceof MockHttpServletRequest) { parameters = ((MockHttpServletRequest) httpServletRequest).getParameterMap(); } else { parameters = ((org.mortbay.jetty.Request) httpServletRequest).getParameters(); } parameters.put(getHiddenFieldId(getForm()), getComponent().urlFor(IOnChangeListener.INTERFACE)); final FormComponent formComponent = (FormComponent) getComponent(); try { if (isUpdateModel()) { formComponent.inputChanged(); formComponent.validate(); if (!formComponent.hasErrorMessage()) { formComponent.valid(); formComponent.updateModel(); } } super.onEvent(target); } catch (RuntimeException e) { Utils.errorLog(AjaxFormSubmittingChangeListenerBehavior.class, e); onError(target); } } /** * @return boolean */ protected boolean isUpdateModel() { return true; } /** * @param form * @return String */ private String getHiddenFieldId(Form form) { try { Form root = form.getRootForm(); return (String) hiddenFieldGetter.invoke(root); } catch (Exception e) { throw new RuntimeException(e); } } } 2010/1/4 Steve Hiller : > Hi All, > > I'm having an issue when using WicketTester with a form that has 3 > DropDownChoice component, which are linked together using the > AjaxFormComponentUpdatingBehavior. In the following code snippet, > selecting from the "brands" DropDownChoice causes the "categories" > DropDownChoice to be filled. Then, selecting from the "categories" > DropDownChoice causes the "titles" DropDownChoice to be filled. > > All of this works fine. However, the call to formTester.submit() > does not trigger the form's onSubmit method. Any ideas what I am > doing wrong? This is using Wicket version 1.3.7. > > Thanks, > Steve > > -- > WicketTester tester = new WicketTester(webapp); > tester.setupRequestAndResponse(); > > FormTester formTester = tester.newFormTester("mainPanel:officeSelectorForm"); > formTester.select("brands", 0); > tester.executeAjaxEvent("mainPanel:officeSelectorForm:brands", "onchange"); > tester.assertComponentOnAjaxResponse("mainPanel:officeSelectorForm:categories"); > formTester.select("categories", 0); > tester.executeAjaxEvent("mainPanel:officeSelectorForm:categories", > "onchange"); > tester.assertComponentOnAjaxResponse("mainPanel:officeSelectorForm:titles"); > formTester.select("titles", 0); > > formTester.submit(); > -- > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
WicketTester -- No Form onSubmit when using Ajax DropDownChoice Component
Hi All, I'm having an issue when using WicketTester with a form that has 3 DropDownChoice component, which are linked together using the AjaxFormComponentUpdatingBehavior. In the following code snippet, selecting from the "brands" DropDownChoice causes the "categories" DropDownChoice to be filled. Then, selecting from the "categories" DropDownChoice causes the "titles" DropDownChoice to be filled. All of this works fine. However, the call to formTester.submit() does not trigger the form's onSubmit method. Any ideas what I am doing wrong? This is using Wicket version 1.3.7. Thanks, Steve -- WicketTester tester = new WicketTester(webapp); tester.setupRequestAndResponse(); FormTester formTester = tester.newFormTester("mainPanel:officeSelectorForm"); formTester.select("brands", 0); tester.executeAjaxEvent("mainPanel:officeSelectorForm:brands", "onchange"); tester.assertComponentOnAjaxResponse("mainPanel:officeSelectorForm:categories"); formTester.select("categories", 0); tester.executeAjaxEvent("mainPanel:officeSelectorForm:categories", "onchange"); tester.assertComponentOnAjaxResponse("mainPanel:officeSelectorForm:titles"); formTester.select("titles", 0); formTester.submit(); --