Search code examples
javascriptjavahtmlgwtmgwt

MGWT ScrollPanel.scrollTo(0, y) leads to Cannot read property 'style' of undefined


I use the ScrollPanel from MGWT and do the following:

  private void scrollToBottom() {
    if (getUiHandlers().isVisible()) {
      final int height = scrollPanel.getOffsetHeight();
      final int heightInt = cellList.getOffsetHeight();
      final int y = scrollPanel.getMaxScrollY();

      if (heightInt >= height) {
          scrollPanel.scrollTo(0, y);
      }
    }
  }

When it comes to this line:

scrollPanel.scrollTo(0, y)

I get the following error:

UncaughtException: (TypeError) : Cannot read property 'style' of undefined 
UncaughtException details: setDelay_1_g$
UncaughtException details: setTransitionsDelay_0_g$ 
UncaughtException details: scrollbarPos_0_g$ 
UncaughtException details: pos_1_g$ 
UncaughtException details: execute_30_g$ 
UncaughtException details: startAnimation_0_g$ 
UncaughtException details: scrollTo_7_g$
UncaughtException details: scrollTo_6_g$
UncaughtException details: scrollTo_5_g$ 
UncaughtException details: scrollTo_3_g$ 

How can I prevent this error?


Solution

  • From the source code and your stack trace it looks like you've experiencing issues with the scrollbar. Does your mgwt scrollpanel always has a scroll when you call scrollTo?

    Also, I highly recommend you to wrap the scrollPanel.scrollTo(0, y); call into Scheduler.get().scheduleDeffered(..your scrollTo call hereenter code here..)