Details
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)
@Override
public synchronized WebRequestCycle setupRequestAndResponse() {
WebRequestCycle result = super.setupRequestAndResponse();
if (m_handlingAjaxRequest)
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.