Hi everybody,
I’m evaluating the possibility to move my projects from facelets to Vaadin.
Being creating a sample project, I faced to a little problem:
Using BeanItemContainer, holding pojos as DataSource for ComboBox, I managed to make my application to work properly, except setting the default value of ComboBox to the value from the Form Item. I’ve read the similar threads from the forum but I did not found any appropriate solution .
Using the code below, the ComboBox grabs and shows the ItemCaptions well:
if (propertyId.equals("comp_country_id")) {
ComboBox cb_country = new ComboBox(p.getProperty("country"), dh.getAllCountries());
cb_country.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_EXPLICIT);
cb_country.setItemCaptionPropertyId("key");
cb_country.setNullSelectionAllowed(false);
return cb_country;
}
In the Table component I see that the CompoBox updates data well, too.
Form item holds data from the bean:
public class companyBBean implements Serializable {
int id;
String comp_name;
String comp_name_rus;
Integer comp_country_id;
...
}
Pojo bean is as simple as it could be:
public class KeyValuePojo implements Serializable {
private Object key;
private Object value;
public KeyValuePojo() {
}
public KeyValuePojo(Object key, Object value) {
this.key = key;
this.value = value;
}
public Object getKey() {
return key;
}
public void setKey(Object key) {
this.key = key;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
@Override
public String toString() {
return value.toString();
}
}
As far as I could understand, the Form should set the default value for the ComboBox and make it to show the text corresponding to its value. Unfortunately, ComboBox having defined value does not show its corresponding key.
Could anybody explain me - where I was wrong?