Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.3.0-beta4
-
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)
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).