How to detect the scrollpanel is still scrolling or not in GWT?

145 views
Skip to first unread message

shiva raaj

unread,
Jul 21, 2016, 4:20:30 AM7/21/16
to GWT Users
Hi Team,
        I need checkpoint to detect the scrollpanel is still scrolling or not. I am sending the server request while scrolling the scroll bar with the delay of 100 milliseconds.
I meant, every 100 milliseconds i am sending the request to server while scrolling. This is fine when i do scroll slowly in the grid. But, when I drag from page top to bottom
I could see there are multiple request is going to server. I want to know is there any flag to delete the long scroll. Please find the code

@Override
        public void onScroll(final ScrollEvent scrollEvent)
        {
        int delay = 100;
super.onScroll(scrollEvent, delay);
        }

I am using GWT class com.google.gwt.dom.client.BrowserEvents.ScrollEvent. I need below kind of logic

@Override
        public void onScroll(final ScrollEvent scrollEvent)
        {
        int delay = 100;
if(stillScollbarScrolling) { //Need boolean flag 
return;
} else {
super.onScroll(scrollEvent, delay);
}
        }
Please help me..

Gilberto

unread,
Jul 21, 2016, 8:48:25 AM7/21/16
to GWT Users
I don't know if that helps with your problem, but you could leave the events as they are today and only make new requests to the server when the previous one were executed.

Something like this:

private boolean requestingServer = false;

public void onScroll(ScrollEvent scrollEvent) {
   
if (requestingServer) return;
    requestingServer = true;
    doServerRequest(new Callback(){ //pseudo code here for a callback mechanism
        public void onResponse(Payload something){
           
requestingServer = false;
        }
    });
}

You can add a logic for a minimum delay between requests as well.

This kind of code works on GWT because it is single threaded. In pure Java you would need to create synchronized blocks to ensure that only one request is being made to the server.

shiva raaj

unread,
Jul 22, 2016, 2:27:37 AM7/22/16
to GWT Users
Thanks for response. But I need consider last request only. Basically I need to skip(eaten) all the previous request. I have logic to eat the request.But Is there any way to find out scroll bar is still scrolling without release the bar.

Thank U

David

unread,
Jul 22, 2016, 2:42:57 AM7/22/16
to GWT Users
maybe you could listen to mousedown/up in combination with scrollevents ?
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Thomas Broyer

unread,
Jul 22, 2016, 4:35:50 AM7/22/16
to GWT Users
I think the generally adopted pattern is to schedule a task 100 or 250ms away, and reschedule it on each scroll event (use a c.g.g.user.client.Timer to be able to reschedule it).
Ideally, you'd also use a "passive event listener", but GWT doesn't expose it: https://blog.chromium.org/2016/05/new-apis-to-help-developers-improve.html (you'd have to use JSNI, which is prone to errors, browser incompatibilities, and memory leaks)

BTW, I almost never use the "scrollbar", I use mousewheel on laptop/desktop and touch on mobile/tablet.

shiva raaj

unread,
Jul 22, 2016, 10:16:41 AM7/22/16
to GWT Users
Is there any way to implement scroll bar with mouse listeners? Bottom line, I want to send the request while doing scrolling. I meant last scrolling height to server if scrolling is delayed for 100 ms or stopped.


On Friday, 22 July 2016 12:12:57 UTC+5:30, DavidN wrote:
maybe you could listen to mousedown/up in combination with scrollevents ?
On Fri, 22 Jul 2016 at 08:27, shiva raaj <stsi...@gmail.com> wrote:
Thanks for response. But I need consider last request only. Basically I need to skip(eaten) all the previous request. I have logic to eat the request.But Is there any way to find out scroll bar is still scrolling without release the bar.

Thank U


On Thursday, 21 July 2016 18:18:25 UTC+5:30, Gilberto wrote:
I don't know if that helps with your problem, but you could leave the events as they are today and only make new requests to the server when the previous one were executed.

Something like this:

private boolean requestingServer = false;

public void onScroll(ScrollEvent scrollEvent) {
   
if (requestingServer) return;
    requestingServer = true;
    doServerRequest(new Callback(){ //pseudo code here for a callback mechanism
        public void onResponse(Payload something){
           
requestingServer = false;
        }
    });
}

You can add a logic for a minimum delay between requests as well.

This kind of code works on GWT because it is single threaded. In pure Java you would need to create synchronized blocks to ensure that only one request is being made to the server.

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsub...@googlegroups.com.

Jens

unread,
Jul 22, 2016, 12:15:29 PM7/22/16
to GWT Users

Is there any way to implement scroll bar with mouse listeners? Bottom line, I want to send the request while doing scrolling. I meant last scrolling height to server if scrolling is delayed for 100 ms or stopped.

Just do what Thomas has suggested. Listen for ScrollEvent and do

void onScroll(ScrollEvent e) {
  sendScrollHeightToServerTimer
.schedule(100);
}

If the timer is not yet scheduled it will be scheduled to execute in 100ms in the future. However if a new scroll event occurs within that 100ms the timer will reset and again wait 100ms. So whenever scrolling is stopped for at least 100ms the timer fires and the timer code executes to read the scroll height and send it to your server.

-- J.
Reply all
Reply to author
Forward
0 new messages