Reputation: 35346
I have this code
@Inject
@DataField("table-col")
SimplePanel tableContainer;
@PostConstruct
public void build() {
scroll(tableContainer.getElement(), this);
tableContainer.addHandler(new ScrollHandler() {
@Override
public void onScroll(ScrollEvent scrollEvent) {
// TODO - Does not trigger
Window.alert("Scroll");
}
}, ScrollEvent.getType());
}
My question is why the tableContainer
Scroll handler does now work when the similar Javascript (JSNI) handler works:
public static native void scroll(Element elem, TablePage instance) /*-{
$wnd.$( elem ).scroll(function() {
if (elem.scrollTop >= (elem.scrollHeight - elem.offsetHeight)) {
[email protected]::scrolledToBottom()();
}
});
}-*/;
What could be wrong here?
Upvotes: 0
Views: 368
Reputation: 491
The SimplePanel
doesn't actually listen to ScrollEvent
, if you want a panel with scroll support you can use ScrollPanel
(which is a simple panel with scrolling support).
ScrollPanel scrollPanel = new ScrollPanel();
scrollPanel.addScrollHandler(new ScrollHandler() {
@Override
public void onScroll(ScrollEvent scrollEvent) {
// TODO - Does not trigger
Window.alert("Scroll");
}
});
In your second way, you're actually adding the event to the element itself, and waiting the event to fired from browser to call your handler. In both ways the event is fired from the browser, but the first one doesn't actually listen to it while the second one listens to it.
Upvotes: 2