if (index == -1)
{
throw new IllegalArgumentException("Behavior " + this +
" was not registered with this component: " + component.toString());
}
ObsoleteRequestParameters params = new ObsoleteRequestParameters();
params.setBehaviorId(String.valueOf(index));
if (request instanceof ServletWebRequest)
{
ServletWebRequest swr = (ServletWebRequest)request;
// If we're coming in with an existing depth, use it. Otherwise,
// compute from the URL. This provides correct behavior for repeated
// AJAX requests: If we need to generate a URL within an AJAX
// request for another one, it needs to be at the same depth as the
// original AJAX request.
int urlDepth = swr.getObsoleteRequestParameters().getUrlDepth();
params.setUrlDepth(urlDepth > -1 ? urlDepth : swr.getDepthRelativeToWicketHandler());
}
final IRequestHandler target = new BehaviorRequestTarget(component.getPage(), component,
listener, params);
return encodeUrlFor(target);