Bug when clearing table selection?

I try to clear a Table selection. Here is the test case:

  1. fill a Table widget with 3 items : a, b, c.
  2. select a.
  3. clear selection (with different methods, see code below).
  4. select c.
  5. print selection : selected items is c, a and not just c.

Am I using the right method to clear selection or is it a bug?

I work with IT Mill 5.2.14. I cannot update to new versions to try, because my project is in production…

import com.itmill.toolkit.Application;
import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.Button.ClickEvent;
import com.itmill.toolkit.ui.Table;
import com.itmill.toolkit.ui.TextField;
import com.itmill.toolkit.ui.Window;
import java.util.Collection;
import java.util.HashSet;

public class TableSelectionBugTestCase extends Application {

    Table table;
    TextField result;

    @Override
    public void init() {
        Window mainWindow = new Window("Test");

        table = new Table();
        table.addContainerProperty("Items", String.class,  null);
        table.addItem( new String[] { "a" }, "a");
        table.addItem( new String[] { "b" }, "b");
        table.addItem( new String[] { "c" }, "c");
        table.setMultiSelect(true);
        table.setSelectable(true);
        table.setHeight("200px");
        table.setWidth("200px");
        mainWindow.addComponent(table);

        Button clearButton = new Button("Clear selection", new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
               clearSelection();
            }
        } );
        mainWindow.addComponent(clearButton);
        Button clearButton2 = new Button("Clear selection 2", new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
               clearSelection2();
            }
        } );
        mainWindow.addComponent(clearButton2);
        Button clearButton3 = new Button("Clear selection 3", new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
               clearSelection3();
            }
        } );
        mainWindow.addComponent(clearButton3);
        Button printButton = new Button("Print selection", new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
               printSelection();
            }
        } );
        mainWindow.addComponent(printButton);

        result = new TextField();
        result.setHeight("200px");
        result.setWidth("200px");
        mainWindow.addComponent(result);

        setMainWindow(mainWindow);
    }
    void clearSelection() {
        table.setValue(null);
    }
    void clearSelection2() {
        table.setValue(new HashSet());
    }
    void clearSelection3() {
        table.unselect( "a" );
        table.unselect( "b" );
        table.unselect( "c" );
    }
    void printSelection() {
        String selection = "";
        for( Object item : (Collection)table.getValue() ) {
            selection = selection + item + ' ';
        }
        result.setValue(selection);
    }

}

It seems to affect latest Vaadin version (6.0.1).

Bug reported here : http://dev.vaadin.com/ticket/3146

Did you set your table to an immediate ( setImmediate(true) ) ? Not having table/tree to be an immediate may also cause strange selection effects.

Thanks for the patch, Ethelle!

I assigned the ticket to Henri, since most of the r&d team is on vacation right now. He’ll check it when he has time to do so.

/Jonatan

Thank you for the detailed problem report, test case and patch. This is now fixed in the 6.0 branch, and will be included in the next nightly build.

As the 5.2 series is no longer actively maintained (except for commercial support customers) and the fix is trivial, I would recommend compiling a corrected version of the 5.2.14 Table class against the 5.2.14 JAR and placing it before the JAR in the classpath, or replacing the class in the JAR.

Ok thank you.

Just to note, this is also fixed in 5.4 series: http://dev.itmill.com/changeset/8406