Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Scrollbars

Andris Lapinsh
10 years ago Dec 23, 2011 12:54pm
Jens Jansson
10 years ago Dec 23, 2011 7:47pm
Andris Lapinsh
10 years ago Dec 24, 2011 8:30pm
Henri Kerola
10 years ago Dec 25, 2011 7:52pm
Andris Lapinsh
10 years ago Dec 27, 2011 10:50am
Henri Sara
10 years ago Dec 27, 2011 12:19pm
Andris Lapinsh
10 years ago Dec 28, 2011 2:46pm
Henri Sara
10 years ago Dec 29, 2011 6:26am
Andris Lapinsh
10 years ago Jan 10, 2012 11:26am
Henri Sara
10 years ago Jan 11, 2012 12:43pm
Dominik Grimmeisen
10 years ago Feb 07, 2012 2:51pm
Henri Sara
10 years ago Mar 15, 2012 8:37am

Andris Lapinsh:

public class VScrollableTable extends VScrollTable{
...
    @Override
    public void updateFromUIDL(final UIDL uidl, final ApplicationConnection client) {
        super.updateFromUIDL(uidl, client);
        String id = uidl.getStringAttribute("scrollPane");
        if (client != null && id != null) {
            
            final boolean immediate = uidl.getBooleanAttribute("immediate");
            
            VScrollTable scrollPane = (VScrollTable) client.getPaintable(id);
            final FocusableScrollPanel scrollBody = (FocusableScrollPanel) scrollPane.getWidget(1);
            
            [b]scrollBody.addScrollHandler[/b](new ScrollHandler() {
                @Override
                public void onScroll(ScrollEvent event) {
                    client.updateVariable(paintableId, "scrollPositions", new Object[] {scrollBody.getScrollPosition(), scrollBody.getHorizontalScrollPosition()}, immediate);
                }
            });
        }
    }
}

...
But with increasing the number of records increasing number of calls to the server :(

This is the problem: a new scroll handler is added on every update. It should only be done once.

Also, I think the "scrollPane" attribute should not be needed as you are in the correct client side instance already.

Last updated on Mar, 15th 2012
Andris Lapinsh
10 years ago Mar 17, 2012 11:07am

Hi All!
Excuse me for a long time did not participate in the discussion.
My research has shown that code fragment does not need:

@Override
    public void updateFromUIDL(final UIDL uidl, final ApplicationConnection client) {
        super.updateFromUIDL(uidl, client);
        String id = uidl.getStringAttribute("scrollPane");
        if (client != null && id != null) {
            
            final boolean immediate = uidl.getBooleanAttribute("immediate");
            
            VScrollTable scrollPane = (VScrollTable) client.getPaintable(id);
            final FocusableScrollPanel scrollBody = (FocusableScrollPanel) scrollPane.getWidget(1);
            
            scrollBody.addScrollHandler(new ScrollHandler() {
                @Override
                public void onScroll(ScrollEvent event) {
                    client.updateVariable(paintableId, "scrollPositions", new Object[] {scrollBody.getScrollPosition(), scrollBody.getHorizontalScrollPosition()}, immediate);
                }
            });
        }
    }

Why?

Because VScrollTable class already have a method onScroll.
We need only to overwrite it.

@Override
	public void onScroll(ScrollEvent event) {
		super.onScroll(event);
		Scheduler.get().scheduleFinally(new Command() {
				public void execute() {
					client.updateVariable(paintableId, "scrollPositions", new Object[] {event.getRelativeElement().getScrollTop(), event.getRelativeElement().getScrollLeft()}, true);
				}
			});
    	}
Last updated on Mar, 17th 2012
Dominik Grimmeisen
9 years ago May 22, 2012 9:05am