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: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
--
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: [email protected]
For additional commands, e-mail: [email protected]