TabSheet: calling setSelectedTab inside SelectedTabChangeListener freezes

Hi all,

My TabSheet tabs are freezing after I call the method setSelectedTab inside the SelectedTabChangeListener.

In order to preserve my application performance, everytime I switch tabs I am replacing the content of the DESELECTED tab with empty content, but I also have to check if the SELECTED tab has empty content in order to replace it with my form and some other stuff. When I do this (tabs.replaceComponent(<empty_component_tab>, <forms_and_stuff_component>)) and then setSelectedTab on the newly replaced tab the component freezes and I cannot switch tabs anymore.

(If I refresh the page (after being freezed), tabs are sill there and I can switch them without any problem.)

If I do not call setSelectedTab on the newly replaced tab the component does not freezes but it selects automatically the first tab and I dont want this…

This is my code:


tabs.addListener(new SelectedTabChangeListener() {

		public void selectedTabChange(SelectedTabChangeEvent event) {

		    Iterator<Component> tabIterator = tabs.getComponentIterator();
		    List<WoDetails> toRemove = new ArrayList<WoDetails>();

		    
		    //Save tabs with content
		    while (tabIterator.hasNext()) {
			Component component = tabIterator.next();
			if (component instanceof WoDetails
				&& component != tabs
					.getSelectedTab()
				&& !((WoDetails) component).isEmptyComponent()) {

			    toRemove.add((WoDetails) component);
			}
		    }

		    //replace them with empty content
		    for (WoDetails detailToRemove : toRemove) {

			WoDetails detailToAdd = new WoDetails(
				(MyApp) tabs.getApplication(),
				detailToRemove.getId(),true /*EMPTY COMPONENT*/);

			tabs.replaceComponent(detailToRemove, detailToAdd);
			tabs.getTab(detailToAdd).setClosable(true);

		    }

		    //replace the selected tab(empty) with one with content
		    if (tabs.getSelectedTab() instanceof WoDetails) {
			
			final WoDetails selectedTab = (WoDetails) tabs.getSelectedTab();

			if (selectedTab.isEmptyComponent()) {

			    WoDetails details = new WoDetails(
				    (WoManagementPortlet) tabs.getApplication(),
				    selectedTab.getId(),false /*NOT EMPTY COMPONENT*/);

			    tabs.replaceComponent(selectedTab, details);
			    tabs.getTab(details).setClosable(true);
			    
			    //select new replaced tab
			    tabs.setSelectedTab(details);

			}

		    }

		}
	    });

Please help me!

Hi David!

It seems that you have endless loop… The thing is that tabs.setSelectedTab(details) fires SelectedTabChangeEvent and your listener method invokes again and again. I think you should add some extra checks whether to invoke tabs.setSelectedTab(details) or not.