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)
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)
super.executeAjaxEvent(component, event);
}