Simon134
(Simon Sparding)
November 3, 2016, 1:50pm
1
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,
Simon
Alain42
(Alain HIRSCH)
November 3, 2016, 3:07pm
2
maybe store the selected index in the session.
when refresh and reload your tabsheet change the selection with the value of the session variable
Simon134
(Simon Sparding)
November 3, 2016, 3:24pm
3
First of all thanks for your answer, Alain.
I guess you thought about something like this:
Component index = myTabSheet.getSelectedTab();
Page.getCurrent().reload();
myTabSheet.setSelectedTab(index);
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.
Alain42
(Alain HIRSCH)
November 3, 2016, 3:36pm
4
No just get the position of the tab to store it to your session scope.
Something like this.
tab.addSelectedTabChangeListener(new SelectedTabChangeListener() {
@Override
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"));
}
Alain42
(Alain HIRSCH)
November 3, 2016, 3:50pm
5
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