Hi, look this solution that i create:
<java> ComboBox comboBox = new ComboBox(getPropertyLabel(formProperty));
comboBox.setRequired(formProperty.isRequired());
comboBox.setRequiredError(getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty)));
comboBox.setEnabled(formProperty.isWritable());
Object firstItemId = null;
Object itemToSelect = null;
RecuperoPF pf = new RecuperoPF(); // this is a class that retrive data from a database
Map <String,String> values = pf.RecuperoDati();
if (values != null) {
for (Entry<String, String> pfEntry : values.entrySet()) {
// Add value and label (if any)
comboBox.addItem(pfEntry.getKey());
if (firstItemId == null) {
firstItemId = pfEntry.getKey(); // select first element
}
String selectedValue = formProperty.getValue();
if (selectedValue != null && selectedValue.equals(pfEntry.getKey())) {
itemToSelect = pfEntry.getKey(); // select first element
}
if (pfEntry.getValue() != null) {
comboBox.setItemCaption(pfEntry.getKey(), pfEntry.getValue());
}
}
}
// Select value or first element
if (itemToSelect != null) {
comboBox.select(itemToSelect);
} else if (firstItemId != null) {
comboBox.select(firstItemId);
}
return comboBox;
</java>