Keep TabSheet selection after reloading the page?

Hey guys,

I have a question on Vaadin TabSheet. In my application I use a TabSheet with two Tabs. I was wondering if there is a way to keep the selected Tab in mind, when refreshing the page. By now, everytime I select the second Tab and then reload the page, it shows me the first Tab again. Is there any way to avoid this?

Thanks in advance,


maybe store the selected index in the session.
when refresh and reload your tabsheet change the selection with the value of the session variable

First of all thanks for your answer, Alain.
I guess you thought about something like this:

Component index = myTabSheet.getSelectedTab();

Am I right?

So I tried this and it does not seem to work. Maybe I have misunderstood what you said, but this is what came to my mind.

No just get the position of the tab to store it to your session scope.

Something like this.

tab.addSelectedTabChangeListener(new SelectedTabChangeListener() {            
            public void selectedTabChange(SelectedTabChangeEvent event) {
                int position = tab.getTabPosition(tab.getTab(event.getComponent()));
                VaadinService.getCurrentRequest().getWrappedSession().setAttribute("indexTab", position);                

And then at the initialisation of your tabsheet to set the position :

if(VaadinService.getCurrentRequest().getWrappedSession().getAttribute("indexTab") != null){
    tab.setSelectedTab((int) VaadinService.getCurrentRequest().getWrappedSession().getAttribute("indexTab"));

Keep in mind that vaadin wil create an other UI when the page is reloaded. (F5)

To keep some data you have to store them to the session