first of all, thank you for creating such a great framework.
I have a problem with setting the default values in ListSelect. Below you will my modified code from the Vaadin 6.4 demo ListSelectMultipleExample.java
Basically I want to set a couple of default values in ListSelect. It works if I only set only one default value, but not for more than one.
So my questions:
Is it even possible to set more than one default values in ListSelect? If yes, can someone give me a hint how to achieve that?
Thank you,
Christian
public class ListSelectMultipleExample extends VerticalLayout
implements Property.ValueChangeListener {
private static final String[] cities =
new String[] { "Berlin", "Brussels", "Helsinki", "Madrid", "Oslo",
"Paris", "Stockholm" };
public ListSelectMultipleExample() {
setSpacing(true);
final ListSelect l = new ListSelect("Please select some cities");
for (final String city : cities) {
l.addItem(city);
final Set<String> selected = new HashSet<String>();
}
l.setRows(7);
l.setNullSelectionAllowed(true);
l.setMultiSelect(true);
l.setImmediate(true);
l.addListener(this);
final Set<String> selected = new HashSet<String>();
selected.add("Berlin");
selected.add("Helsinki");
l.select(selected);
addComponent(l);
}
/*
* Shows a notification when a selection is made.
*/
public void valueChange(final ValueChangeEvent event) {
getWindow().showNotification("Selected cities: " + event.getProperty());
}
}
I'trying with the two options
Iterator it=publication.getAutors().iterator();
final Set<Integer> selected = new HashSet<Integer>();
while (it.hasNext()){
Author author=(Author) it.next();
selected.add(author.getId());
}
ListSelect list=(ListSelect)getField("idauthor");
list.setValue(selected)
And continues not working…!!
I don’t know what is happening!! Any idea that what could be the problem?
How did you specify the property type for the values?
It seems since you are directly setting the select’s value (hashset), you need to be sure you set the ListSelect as setMultiSelect(true) and then you need to have built the select’s possible values correctly using Integer values in your case. And then the property that represents your Integer field id needed to be specified as type java.util.Set.class.
It doesn’t seem like you are using an Item to set the values in your Form’s ListSelect, so I’m not sure how to do it all directly. The key is that you somehow need to tell the ListSelect that the values are a Set type (with beans, the get/set methods just use Set, and with Items, you need to addItemProperty specifying the type of Set like above). Otherwise, I’m not sure how to do it.