1

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?

Michael
  • 32,527
  • 49
  • 210
  • 370
  • Did you call scrollTo before the ScrollPanel is added to the DOM? See my updated answer http://stackoverflow.com/a/35016359/1417396 – robert Jan 26 '16 at 19:57

2 Answers2

1

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..)

1

1) Make sure you call either setScrollingEnabledY(true) or setShowVerticalScrollBar(true) or setShowScrollBarY(true).

And none of them with (false).

2) The scrollbar is only initialised upon a scrollPanel.refresh() call, which is also called asynchronously in onAttach() when the ScrollPanel is attached to the DOM.

2a) So make sure you do not call scrollTo before the ScrollPanel is added to the DOM (shown).

2b) And wrap the scrollTo call in a timer.schedule(1) to address the asynchronously call in onAttach().

robert
  • 978
  • 7
  • 17
  • I did ``scrollPanel.setScrollingEnabledX(false); scrollPanel.setShowHorizontalScrollBar(false); scrollPanel.setShowVerticalScrollBar(true); scrollPanel.setBounce(false); scrollPanel.setHideScrollBar(false);`` in the View's constructor. – Michael Jan 26 '16 at 21:30