How to get ListSelect working in multiselect mode?

Hi,

I’ve defined a ListSelect component containing Gene objects. The list is populated as given below:

[code]
genesFld.addContainerProperty(“genename”, String.class, null);
genesFld.setItemCaptionPropertyId(“genename”);

GeneSet gs = new GeneSet();
for (int i=0; i < gs.getGeneSet().size(); i++) {
Gene gene = gs.getGeneSet().get(i);
Item item = genesFld.addItem(gene);
item.getItemProperty(“genename”).setValue(gene.toString());
}
[/code]As a test I want to pre-select two Genes like:

Set<Item> gis = new HashSet<Item>(); gis.add(genesFld.getItem(gs.getGeneSet().get(0))); gis.add(genesFld.getItem(gs.getGeneSet().get(3))); genesFld.setValue(gis); The following commands:

Set<Item> values=(Set<Item>) genesFld.getValue(); System.out.println("SelectList Genes: " + values); do show me the pre-selected Genes!

But, I’d also expect the pre-selected Gene items to be highlighted in the ListSelect component, but they aren’t!
Why?

Regards,
Gerard

P.S. Using Vaadin 7.2.0!

Hi,

you should use Item IDs, not Items when setting the value. So you need to change your code to:

Set<Object> gis = new HashSet<Object>(); gis.add(gs.getGeneSet().get(0)); gis.add(gs.getGeneSet().get(3)); genesFld.setValue(gis); -tepi

Hi,

Thanks for your answer!

(Sorry for this delayed response!)

Regards,
Gerard