Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-1733

WicketTester doesn't include form submitting component id in form submissions

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.3.3
    • 1.4.11, 1.5-M2.1
    • wicket
    • None

    Description

      When submitting a form with an AJAX link (or other AJAX-based control), WicketTester doesn't include the id of the component that 'submitted' the form, meaning that in situations with nested forms, the wrong form's onSubmit() method may be called.

      We're working around this problem by overriding the clickLink() and executeAjaxEvent() methods as follows:

      @Override
      public void clickLink(String path, boolean isAjax) {
      Component linkComponent = getComponentFromLastRenderedPage(path);
      if (linkComponent instanceof AjaxSubmitLink)

      { AjaxSubmitLink link = (AjaxSubmitLink) linkComponent; Map<String, Object> requestParams = getParametersForNextRequest(); requestParams.put(link.getInputName(), "x"); }

      super.clickLink(path, isAjax);
      }

      @Override
      public void executeAjaxEvent(Component component, String event) {
      // Code borrowed from BaseWicketTester.

      // Run through all the behavior and select the LAST ADDED behavior which
      // matches the event parameter.
      AjaxEventBehavior ajaxEventBehavior = null;
      List behaviors = component.getBehaviors();
      for (Iterator iter = behaviors.iterator(); iter.hasNext() {
      IBehavior behavior = (IBehavior) iter.next();

      // AjaxEventBehavior is the one to look for
      if (behavior instanceof AjaxEventBehavior) {
      AjaxEventBehavior tmp = (AjaxEventBehavior) behavior;

      if (event.equals(tmp.getEvent()))

      { ajaxEventBehavior = tmp; }

      }
      }

      // Workaround: If the behaviour is an AjaxFormSubmitBehavior then add the
      // component's input name.
      if (ajaxEventBehavior instanceof AjaxFormSubmitBehavior
      && component instanceof FormComponent)

      { String inputName = ((FormComponent) component).getInputName(); Map<String, Object> requestParams = getParametersForNextRequest(); requestParams.put(inputName, "x"); }

      super.executeAjaxEvent(component, event);
      }

      Attachments

        Activity

          People

            ivaynberg Igor Vaynberg
            david.shepherdson David Shepherdson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: