TabSheet and components with scrollbar

Hi,

I noticed a difference of behavior between vaadin 6 and vaadin 7.
When a TabSheet contains components with a scrollbar, the position of the scrollbar is not conserved when we change of tab. Each time I com back to a tab, the scrollbar of the component inside this tab is back to the top…

It was working well under vaadin 6 :frowning:
How can I solve this problem ?

Thanks

Or which methods I must extend on a scrollable component to keep the scroll position ?

I tryed to send the scroll position from the onDetach function but the rpc seems to be already close because the server don’t receive anything ???

I need help please :frowning:

I finally chose to create my “own” TabSheet component.
My POC if it can help somebody :

package org.vaadin.aceeditordemo;

import java.util.HashMap;
import java.util.Map;

import com.vaadin.server.Resource;
import com.vaadin.ui.Component;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TabSheet.CloseHandler;
import com.vaadin.ui.TabSheet.Tab;
import com.vaadin.ui.TextField;
import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import com.vaadin.ui.TabSheet.SelectedTabChangeListener;
import com.vaadin.ui.CssLayout;

public class MyTabSheet extends CssLayout {

    private static final long serialVersionUID = -2606375950491980753L;

    private static final String DISPLAY_NONE_CLASS_NAME = "displayNone";

    private TabSheet tabSheet = new TabSheet();
    private Map<Integer, Component> hashToComponentMap = new HashMap<>();
    private Component currentTab;

    /**
     * @see TabSheet#TabSheet()
     */
    public MyTabSheet() {
        addListeners();
        addComponent(tabSheet);
    }

    /**
     * @see TabSheet#TabSheet(Component...)
     */
    public MyTabSheet(Component... components) {
        this();
        addComponents(components);
    }

    /**
     * @see TabSheet#addTab(Component, String)
     */
    public Tab addTab(Component c, String caption) {
        return addTab(c, caption, null);
    }

    /**
     * @see TabSheet#addTab(Component, String, Resource)
     */
    public Tab addTab(Component c, String caption, Resource icon) {
        return addTab(c, caption, icon, tabSheet.getComponentCount());
    }

    /**
     * @see TabSheet#addTab(Component, String, Resource, int)
     */
    public Tab addTab(Component tabComponent, String caption, Resource icon,
            int position) {
        int hash = tabComponent.hashCode();
        hashToComponentMap.put(hash, tabComponent);

        // add a Component with the reference (hash) of the real component to
        // display. This component will never be displayed
        TextField t = new TextField("" + hash);
        t.addStyleName(DISPLAY_NONE_CLASS_NAME);

        // add all components with "display: none", the
        // SelectedTabChangeListener will display the tab to display
        addComponent(tabComponent);
        tabComponent.addStyleName(DISPLAY_NONE_CLASS_NAME);

        return tabSheet.addTab(t, caption, icon, position);
    }

    private void addListeners() {
        tabSheet.addSelectedTabChangeListener(new SelectedTabChangeListener() {

            private static final long serialVersionUID = 3262360390619159986L;

            @Override
            public void selectedTabChange(SelectedTabChangeEvent event) {
                int hash = Integer.valueOf(tabSheet.getSelectedTab().getCaption());
                Component selectedTab = hashToComponentMap.get(hash);
                selectedTab.removeStyleName(DISPLAY_NONE_CLASS_NAME);

                if (currentTab != null)
                    currentTab.addStyleName(DISPLAY_NONE_CLASS_NAME);
                currentTab = selectedTab;
            }
        });
        
        tabSheet.setCloseHandler(new CloseHandler() {
            
            private static final long serialVersionUID = -3607403614494881456L;

            @Override
            public void onTabClose(TabSheet tabsheet, Component tabContent) {
                tabsheet.removeComponent(tabContent);
                int hash = Integer.valueOf(tabContent.getCaption());
                Component c = hashToComponentMap.remove(hash);
                if (c != null)
                    removeComponent(c);                
            }
        });
    }

}