What kind of behavior do you have now and what kind do you want?
When there is 500ms throttle and handling each throttled request takes
few seconds, you end up queuing and handling each request. If you are
interested in only the last request, this solution clears the pending
requests so server gets less requests and the last request gets
handled faster.
If your throttled request gets handled before the next request, this
solution doesn't bring any new behavior.
Quoting JohannesK johannes.kuus...@eficode.fi:
Does this solution actually work though? I tried it and I don't see any
behaviour I wouldn't get from just the throttle delay. Is there something I
need to change in this to use it? Possibly the channel names?
Antti Mattila wrote:
Problem:
I want to validate input as user types it, but validation takes a long
time
on the server. When validation result for the first input is returned,
user
might have caused several more input events to be validated. These
validation requests are pending execution on Wicket Ajax Channel. At this
point I'm only interested in validating the latest input, but before this
happens, all pending validation requests are processed. This is
unnecessary
and takes a lot of time so I want to cancel all the pending requests.
Solution:
I did this by using named Channel and clearing all pending requests before
requesting the latest validation. I couldn't find a solution for this
problem, so I'm posting it here. Hopefully this might help someone else
and
please give me some feedback if this solution was not a good one.
Thanks,
Antti Mattila
Here's the code:
public class ClearPendingAjaxRequests extends AjaxCallDecorator {
private final String clearPendingRequestsScript;
public ClearPendingAjaxRequests(final String channel) {
clearPendingRequestsScript = if (typeof
Wicket.channelManager.channels[' + channel + '] != 'undefined')
Wicket.channelManager.channels[' + channel + '].callbacks = new
Array();;
}
@Override
public CharSequence decorateScript(final CharSequence script) {
return clearPendingRequestsScript + script;
}
}
public class UsersInputFieldOnChangeAjaxBehavior extends
AjaxFormComponentUpdatingBehavior {
public UsersInputFieldOnChangeAjaxBehavior() {
super(onkeyup);
setThrottleDelay(Duration.milliseconds(500));
}
@Override
protected IAjaxCallDecorator getAjaxCallDecorator() {
return new ClearPendingAjaxRequests(getChannelName());
}
@Override
protected String getChannelName() {
return ChannelForValidatingThisSpecificInput;
}
@Override
protected void onUpdate(final AjaxRequestTarget target) {
// Validate user's input, this takes a long time.
// Update UI.
}
}
-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
--
View this message in context:
http://www.nabble.com/Cancelling-pending-Ajax-requests-tp23523655p23810657.html
Sent from the Wicket - User mailing list archive at Nabble.com.
-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org