Combobox with BeanItemContainer and BeanFieldGroup throw Conversion exception
I make some test to see how can bind combobox to some bean property, but i
got an exception: "ConversionException: Could not convert value to String
at ..........." My sample work ok with indexedContainer for combobox, but
i have some trouble with BeanItem container. What i have: 1. TestCountry,
simple java bean for BeanItemContainer (i don't put here setter and getter
or constructor for simplicity):
public class TestCountry implements Serializable {
private String name;
private String shortName;
}
instantiation of BeanItemContainer
BeanItemContainer<TestCountry> _data = new
BeanItemContainer<TestCountry>(TestCountry.class);
_data.addItem(new TestCountry("Afganistan","AF"));
_data.addItem(new TestCountry("Albania","AL"));
bean filed group. Here TestBean is another bean with simple string
property's ("firstName","phone","contry")
BeanFieldGroup<TestBean> binder = new
BeanFieldGroup<TestBean>(TestBean.class);
combobox
ComboBox myCombo = new ComboBox("Select your country", _data);
essential code
binder.bind(myCombo, "country");
When i try to commit the binder i got an error about conversion problem to
string. From what i understand reading books and vaadin api,
BeanItemContainer uses the beans themselves as identifiers and (here may
be wrong) binder use item identifier to bind property. So here is the
problem, conversion from Bean to string. I try'it to implement toString(),
hash() and equals() on my TestCountry bean but without success. What can
do to use BeanItemContainer in this scenario?
Thanks in advance!!
No comments:
Post a Comment