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

Wicket-Ajax header always false with BaseWicketTester

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 1.3.0-beta3, 1.3.0-beta4
    • 1.3.0-rc2
    • wicket
    • None

    Description

      The 'Wicket-Ajax' header is always missing when using BaseWicketTester, even when the request should be an AJAX request.

      The specific case we have is an AjaxLink that, when clicked, shows a modal window. We call BaseWicketTester's clickLink(String) method to simulate clicking the link. The link's onClick(...) method is called with an appropriate AjaxRequestTarget; however, ModalWindow's onBeforeRender() tests whether the request is an AJAX request (using ((WebRequest)getRequest()).isAjax()) and, if it's not, hides the content panel.

      The problem is that the isAjax() call tests whether the HttpServletRequest's 'Wicket-Ajax' header is present and 'true'; when running this code with BaseWicketTester, the header is never there, and so the modal window's content is never shown.

      We have worked around the problem by overriding clickLink(String, boolean) and setupRequestAndResponse() as follows:

      private boolean m_handlingAjaxRequest = false;

      @Override
      public synchronized void clickLink(String path, boolean isAjax)

      { m_handlingAjaxRequest = isAjax; super.clickLink(path, isAjax); m_handlingAjaxRequest = false; }

      @Override
      public synchronized WebRequestCycle setupRequestAndResponse() {
      WebRequestCycle result = super.setupRequestAndResponse();
      if (m_handlingAjaxRequest)

      { // Set AJAX header. getServletRequest().addHeader( "Wicket-Ajax", "true"); // *Don't* copy it to the response, even though // MockWebApplication's setupRequestAndResponse() does. }

      return result;
      }

      (I found that if I copied the 'Wicket-Ajax' header to the response, as done by MockWebApplication's setupRequestAndResponse(), it caused all AJAX clicks to misbehave.)

      Hence, it would seem that if BaseWicketTester's clickLink(String, boolean) method were modified to set the 'Wicket-Ajax' header as appropriate, modal windows – and, presumably, any other things that rely on the request returning true from isAjax() – would work as expected.

      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: