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

BaseWicketTester doesn't call detach() for AJAX requests

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.3.0-beta4
    • 1.3.0-rc2
    • None
    • None

    Description

      BaseWicketTester doesn't call detach() on the request cycle when clicking an AJAX link. This does not match the behaviour when running in a 'real' servlet container, when detach() does get called for the same AJAX requests.

      One side effect of this is that AJAX header contributions are left in the page and cause problems when the next request occurs. For example, we have a page that we want to test. It contains an AJAX link and a (non-AJAX) form. We click the link, then fill in and submit the form. However, an exception is thrown when submitting the form as it tries to render the AJAX header contribution left over from the AJAX page. (Exception comes from checkHeaderRendering() in AjaxHeaderResponse.)

      We are working around this problem by overriding BaseWicketTester's clickLink(String, boolean) method, so as to hang onto the RequestCycle and call its detach() method once the response has been made for AJAX requests; for example:

      RequestCycle requestCycle = null;

      if (linkComponent instanceof AjaxLink)

      { ... setupRequestAndResponse(); requestCycle = createRequestCycle(); AjaxRequestTarget target = new AjaxRequestTarget(link.getPage()); requestCycle.setRequestTarget(target); link.onClick(target); target.respond(requestCycle); }

      ...
      if (requestCycle != null)

      { // Detach the requestCycle, so that state isn't left around // for any further use of this page. requestCycle.detach(); }

      This should be a very simple one-line fix (well, 1 x the number of AJAX requests made in BaseWicketTester's clickLink(...) method, which is 3).

      Attachments

        Activity

          People

            Unassigned Unassigned
            david.shepherdson David Shepherdson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: