I’m trying to create a custom component to Vaadin that loads a component from the server side when the user has scrolled the browser window far enough to show the component. Is there a way of catching the window scroll event on the client side of Vaadin? The basic GWT way of doing it
Window.addWindowScrollHandler(new Window.ScrollHandler() {
@Override
public void onWindowScroll(ScrollEvent event) {
... some code ...
}
});
does not seem to work as the body element of the document is never scrolled in Vaadin.
You’ve stumbled upon a, yet another, Vaadin gotcha: the main scrollable element in Vaadin apps is not the BODY element, but a DIV element called VView. You should listen for that element’s scroll events.
But since VView is not a ScrollPanel and does not implement the HasScrollHandlers interface, adding a listener for its scroll events is basically impossible at the moment. The only option you have is to add the scroll event listener by using GWT’s native JS interface, which is almost always discouraged (and cumbersome too, I might add).
This is definitely worthy of a ticket, please create a new issue at
dev.vaadin.com
And regarding your custom widget: keep in mind that VView is not the only scrollable element in Vaadin apps. You have Panels and SplitPanels as well…