Hi Goran! Great component! I wrote following test code. Test 1 works very

Hi Goran! Great component!

I wrote following test code. Test 1 works very good. But in Test 2 I found a problem. After setting the values in Test 2 and after opening the selection box no element ist selected in the list but “Two” and “Three” should be selected. “Two” and “Three” are shown in the MultiselectBox, but not as selection in the list. With datatype String the box works great, but not with a custom type.

Is this an error or not yet implemented?

Thank you very much,
Thomas

    **// TEST 1**
    final org.vaadin.gatanaso.MultiselectComboBox<java.lang.String> multi1 = new org.vaadin.gatanaso.MultiselectComboBox<java.lang.String>();

    final java.util.ArrayList<java.lang.String> itemList1 = new java.util.ArrayList<java.lang.String>();
    itemList1.add("One");
    itemList1.add("Two");
    itemList1.add("Three");
    itemList1.add("Four");

    multi1.setItems(itemList1);

    final java.util.TreeSet<java.lang.String> selection1 = new java.util.TreeSet<java.lang.String>();
    selection1.add("Two");
    selection1.add("Three");

    multi1.setValue(selection1);

    content.add(multi1);
    
    **// TEST 2**
    final org.vaadin.gatanaso.MultiselectComboBox<de.tricept.vaadin.ui.helper.LabelValue> multi2 = new org.vaadin.gatanaso.MultiselectComboBox<de.tricept.vaadin.ui.helper.LabelValue>();
    multi2.setItemLabelGenerator(de.tricept.vaadin.ui.helper.LabelValue::getLabel);

    final java.util.ArrayList<de.tricept.vaadin.ui.helper.LabelValue> itemList2 = new java.util.ArrayList<de.tricept.vaadin.ui.helper.LabelValue>();
    itemList2.add(new de.tricept.vaadin.ui.helper.LabelValue("One", 1));
    itemList2.add(new de.tricept.vaadin.ui.helper.LabelValue("Two", 2));
    itemList2.add(new de.tricept.vaadin.ui.helper.LabelValue("Three", 3));
    itemList2.add(new de.tricept.vaadin.ui.helper.LabelValue("Four", 4));

    multi2.setItems(itemList2);

    final java.util.TreeSet<de.tricept.vaadin.ui.helper.LabelValue> selection2 = new java.util.TreeSet<de.tricept.vaadin.ui.helper.LabelValue>();
    selection2.add(new de.tricept.vaadin.ui.helper.LabelValue("Two", 2));
    selection2.add(new de.tricept.vaadin.ui.helper.LabelValue("Three", 3));

    multi2.setValue(selection2);

    content.add(multi2); 
	
	
	
	
	
	
	public class LabelValue implements java.io.Serializable, java.lang.Comparable<de.tricept.vaadin.ui.helper.LabelValue> {
/**
 * serialVersionUID
 */
private static final long      serialVersionUID = -7311339755841714861L;

private final java.lang.String label;
private final java.lang.Object value;

/**
 * @param newLabel
 * @param newValue
 */
public LabelValue(java.lang.String newLabel, java.lang.Object newValue) {
    this.label = newLabel;
    this.value = newValue;
}

/**
 * @return the value
 */
public java.lang.Object getValue() {
    return this.value;
}

/**
 * @return the label
 */
public java.lang.String getLabel() {
    return this.label;
}

/**
 * ToString
 */
@Override
public java.lang.String toString() {
    return this.label;
}

/**
 * Compare
 */
@Override
public int compareTo(de.tricept.vaadin.ui.helper.LabelValue newO) {
    return this.toString().compareTo(newO.toString());
}

}

Hi Thomas,

Thank you for the feedback.

That is very interesting.

Have you tried the above test, but with hashCode() and equals() overridden for the LabelValue class?

BR,

Goran

Hello Goran,

thank you very much.

Implementig these two methods solved my problem.

Greetings
Thomas