Issue with TabSheet.setSelectedTab(int position)

Hi,

Observed with Vaadin version 7.2.0, same code works fine with &.1.14
In my application there are 5 tabs, each tab contains some components.
Following is the desired functinality:

  1. Tab at position 0 is set as selected by default
  2. User click on tab at postion 4
  3. Now depending on some business logic it will be checked if all operation on tab at position 0 are completed or not
  4. If operations on tab at position 0 are not completed then setSelectedTab(0)

Issue:

  1. When setSelectedTab(0) is used all tabs in tabsheet becomes unresponsive, tabs are clickable but tab containt is not loaded.
  2. This scenarios fails only when Tab at position x is selected where x=0 at then user clicks on Tab 5
  3. If user has selected Tab at position y, where y!=0 code works fine

Please suggest how to solve this issue.

Following is the code for reference:

package com.example.vaadindemo;

import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import com.vaadin.ui.TabSheet.SelectedTabChangeListener;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
public class TabsheetDemo extends UI {

    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout vLayout = new VerticalLayout();

        final TabSheet tabsheet = new TabSheet();
        final VerticalLayout tab1 = new VerticalLayout();
        final VerticalLayout tab2 = new VerticalLayout();
        final VerticalLayout tab3 = new VerticalLayout();
        final VerticalLayout tab4 = new VerticalLayout();
        final VerticalLayout tab5 = new VerticalLayout();

        tab1.addComponent(new Label("Label A"));
        tab2.addComponent(new Label("Label B"));
        tab3.addComponent(new Label("Label C"));
        tab4.addComponent(new Label("Label D"));
        tab5.addComponent(new Label("Label E"));

        tabsheet.addTab(tab1, "Tab 1");
        tabsheet.addTab(tab2, "Tab 2");
        tabsheet.addTab(tab3, "Tab 3");
        tabsheet.addTab(tab4, "Tab 4");
        tabsheet.addTab(tab5, "Tab 5");
        tabsheet.setSelectedTab(0);

        tabsheet.addSelectedTabChangeListener(new SelectedTabChangeListener() {

            @Override
            public void selectedTabChange(SelectedTabChangeEvent event) {
                if (tabsheet.getSelectedTab().equals(tab5)) {
                    boolean flag = false;
                    // TODO flag = ifOperationsOnTabDone(){.....}
                    // Some business logic to check if the operations on current
                    // selected tab completed or not
                    if (!flag) {
                        // Set focus back to first tab in tabsheet
                        tabsheet.setSelectedTab(0);
                        Notification.show("Focus set back to tab at position 0");
                    }
                }
            }
        });

        vLayout.addComponent(tabsheet);
        vLayout.setWidth("400px");
        vLayout.setHeight("300px");
        setContent(vLayout);
    }
}

Regards,
Kunal Patil

Just did a little bit of testing and it seem like a Button setting the selected Tab…

Button btn = new Button(); btn.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { tabsheet.setSelectedTab(tab3); } }); vLayout.addComponent(btn); …can make the Tabsheet “unstuck” again.

Also does putting it into a Thread/Runnable and executing it a bit later (needs syncing though)

The issue still exists with Vaadin version 7.3.0
I have created ticket to Vaadin Trac

http://dev.vaadin.com/ticket/14710