Keeping selected tab index of Vaadin Tabsheet

I needed a way to keep the selected state of a Vaadin Tabsheet when redraw.There was no built-in method to do this. So this method was implemented to get the currently selected tab index. Hope this will be useful for others as well.


//return selected tab index of a tabsheet
	private int getSelectedTabIndex(TabSheet tabSheet){
		int selectedTab=0;
		Component selected_tab_id = tabSheet.getSelectedTab();
		
		Iterator<Component> tabIterator = tabSheet.getComponentIterator();
		int tabindex = 0;
	    while ( tabIterator.hasNext() ){
	      
	      if(selected_tab_id==tabIterator.next()){
	    	  selectedTab=tabindex;
	      }
	      
	      tabindex++;
	    }
	    
		return selectedTab;
	}