yes, there is a scrollbar and I scrolled it down ;-).
I just moved to Vaadin 14 and reduced the sample app to the max.
The listener is bound to every available element, but never called.
@Route("")
@Theme(value = Lumo.class, variant = Lumo.LIGHT)
public class OverView extends Div
{
public OverView()
{
getStyle().set("background-color", "#009EE2");
setHeight("9000px");
DomEventListener l = e -> System.out.println("invoked!");
Div div = new Div();
add(div);
div.getElement().addEventListener("scroll", l);
getElement().addEventListener("scroll", l);
UI.getCurrent().getElement().addEventListener("scroll", l);
}
}
I just tested the same above code with another event and it worked
DomEventListener l = e -> System.out.println("invoked!");
Div div = new Div();
add(div);
div.getElement().addEventListener("mouseleave", l);
getElement().addEventListener("mouseleave", l);
UI.getCurrent().getElement().addEventListener("mouseleave", l);
DomEventListener l = e -> System.out.println("invoked!");
Div div = new Div();
add(div);
div.getElement().addEventListener("scroll", l);
getElement().addEventListener("scroll", l);
UI.getCurrent().getElement().addEventListener("scroll", l);
More update on this, I can see the ‘Scroll’ event got loaded from ‘Inspect’
I’ve understood it as : you had added a listener in the console and you can see that event is fired inside the listener.
So it works if you add a JS listener in the console, right ?
Which element you had used to add a listener ?
More update on this, I can see the ‘Scroll’ event got loaded from ‘Inspect’
I’ve understood it as : you had added a listener in the console and you can see that event is fired inside the listener.
So it works if you add a JS listener in the console, right ?
Which element you had used to add a listener ?
ok. No, I have not added any element from console. I just found the listener by inspect element and then from the chrome inspect i saw a tab ‘Event Listener’ which have the value ‘scroll’
Once I remove the java code, the value also gets removed. So, in my understanding it is controlled from Java code.
Thank you for the input Denis. However, I would still like to have the event handler to work for the java code.
Since, I need to add the scroll event to div. I cannot use a window object inside java code to have the scroll working.
div.getElement().addEventListener(“scroll”, l);
strange thing is this works for mouseleave and other events, why not for ‘Scroll’ ?
Anticipating your following question “how to call a Java side from the client side listener” you may add a @ClientCallable method to your component and then you may use inside the client side function this.$server.callServerSide().