6 Replies Latest reply on Apr 10, 2007 12:11 PM by Jason Young

    proposed solution for remembering scroll position

    Jason Young Newbie

      I have a problem where an a4j:outputPanel is larger than its container, so we have scrollbars (using css height & overflow properties). However, when the panel is rerendered, the scroll position is lost.

      I initially attempted to fix this by setting the scrollTop attribute in the onComplete handler. However, this produced jumpiness that wouldn't be acceptable to an enduser. So instead, I tried adding it to the updatePagePart handler in the AJAX.js file. Adjusting the scrollTop at this level seems to work much better, since I can't tell visually that it is happening.

      Can the maintainers of A4J tell me if this is something that could be accepted into the main CVS tree? I don't care if want to change how I did it, but having this functionality in the library itself would be a great help.

      Thanks in advance!

       if ( oldnode ) {
       var oldScrollTop = 0;
       if (oldnode.scrollTop > 0)
       oldScrollTop = oldnode.scrollTop;
       LOG.debug("oldScrollTop = " + oldScrollTop);
       var anchor = oldnode.parentNode ;
       // need to check for firstChild due to opera 8 bug with hasChildNodes
       LOG.debug("Replace content of node by outerHTML()");
       oldnode.outerHTML = new XMLSerializer().serializeToString(newnode);
       if (oldScrollTop > 0) {
       LOG.debug("setting scrollTop = " + oldScrollTop);
       oldnode.scrollTop = oldScrollTop;
       } else {
       var importednode ;
       importednode = window.document.importNode(newnode, true);
       LOG.debug("Replace content of node by replaceChild()");
       if (oldScrollTop > 0) {
       LOG.debug("setting scrollTop = " + oldScrollTop);
       importednode.scrollTop = oldScrollTop;