}
AjaxLink<?> link = (AjaxLink<?>)linkComponent;
setupRequestAndResponse(true);
WebRequestCycle requestCycle = createRequestCycle();
callOnBeginRequest(requestCycle);
AjaxRequestTarget target = getApplication().newAjaxRequestTarget(link.getPage());
requestCycle.setRequestTarget(target);
link.onClick(target);
// process the request target
processRequestCycle(requestCycle);
}
// AjaxFallbackLinks is processed like an AjaxLink if isAjax is true
// If it's not handling of the linkComponent is passed through to the
// Link.
else if (linkComponent instanceof AjaxFallbackLink && isAjax)
{
AjaxFallbackLink<?> link = (AjaxFallbackLink<?>)linkComponent;
setupRequestAndResponse(true);
WebRequestCycle requestCycle = createRequestCycle();
AjaxRequestTarget target = getApplication().newAjaxRequestTarget(link.getPage());
requestCycle.setRequestTarget(target);
link.onClick(target);
// process the request target
processRequestCycle(requestCycle);
}
// if the link is an AjaxSubmitLink, we need to find the form
// from it using reflection so we know what to submit.
else if (linkComponent instanceof AjaxSubmitLink)
{
// If it's not ajax we fail
if (isAjax == false)
{
fail("Link " + path + "is an AjaxSubmitLink and " +
"will not be invoked when AJAX (javascript) is disabled.");
}
AjaxSubmitLink link = (AjaxSubmitLink)linkComponent;
// We cycle through the attached behaviors and select the
// LAST matching behavior as the one we handle.
List<IBehavior> behaviors = link.getBehaviors();
AjaxFormSubmitBehavior ajaxFormSubmitBehavior = null;
for (IBehavior behavior : behaviors)
{
if (behavior instanceof AjaxFormSubmitBehavior)
{
AjaxFormSubmitBehavior submitBehavior = (AjaxFormSubmitBehavior)behavior;
ajaxFormSubmitBehavior = submitBehavior;
}
}
String failMessage = "No form submit behavior found on the submit link. Strange!!";
notNull(failMessage, ajaxFormSubmitBehavior);
WebRequestCycle requestCycle = setupRequestAndResponse(true);
submitAjaxFormSubmitBehavior(linkComponent, ajaxFormSubmitBehavior);
// Ok, finally we "click" the link
ajaxFormSubmitBehavior.onRequest();