Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Binding objects in native select to an object in the form bean
I have a form where in i have a Nativeselect which is populated with Cd Objects.
When the user selects an item from the dropdown i need to populate the FormBean with the selected Cd object.
Please look at my form bean; How will i Map the selected Cd object to the bean.
My vaadin version is 6.8.0.nightly-20111122-c22085.
public class VisitInfo {
private Cd selectedVisitAction;
private List<Cd> visitActions = new ArrayList<Cd>();
}
In FormFieldFactory
-------------------------
if (WebAppConstants.VISIT_ACTIONS.equals(propertyId)) {
final NativeSelect typeSelect = getNativeSelect("treatmentrealization.form.action");
final BeanItemContainer<Cd> container = new BeanItemContainer<Cd>(Cd.class , visitInfo.getVisitActions());
typeSelect.setContainerDataSource(container);
typeSelect.setItemCaptionMode(Select.ITEM_CAPTION_MODE_PROPERTY);
typeSelect.setItemCaptionPropertyId("displayName");
typeSelect.addListener(new Property.ValueChangeListener() {
return typeSelect;
}
When the form is submitted i get
com.vaadin.data.Property$ConversionException: java.lang.NoSuchMethodException: java.util.List.<init>(java.lang.String)
at com.vaadin.data.util.MethodProperty.convertValue(MethodProperty.java:697)
at com.vaadin.data.util.MethodProperty.setValue(MethodProperty.java:666)
at com.vaadin.ui.AbstractField.commit(AbstractField.java:258)
at com.vaadin.ui.AbstractField.setWriteThrough(AbstractField.java:378)
at com.vaadin.ui.Form.setWriteThrough(Form.java:474)
at com.logica.medi.hcmu.webapp.components.form.VisitingDataForm.commit(VisitingDataForm.java:103)
I'm sorry I don't have time to actually try this, but here goes:
First of all the ConversionException gets thrown because the property value type List doesn't have a constructor from String. Usually property implementations try to fallback for String conversion if there's a mismatch between property value and type. In this case even that fails.
But the actual problem is that your visitActions is a type of List and the NativeSelect value type (selection) is Cd object. In multiselect mode the value type would be Set. Anyway List is not assignable from Set so visitActions type should be Collection or Set.
Finally however even that doesn't help because NativeSelect doesn't support multiselect mode so you should use Select instead of NativeSelect.
BUT long story even longer. I guess you don't want to have visitActions actually in the form, but create the NativeSelect for property selectedVisitAction and not for visitActions.
Thanks Johannes
creating the Native select for selectedVisitAction worked like Charm. Thanks again
Regards
Ajay