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.
ComboBox Converter
Hello Vaadin gurus,
I am trying to apply a converter to combobox and having extremely difficulty getting it work.
Issue #1 - When I apply a converter to a combobox Eclispse Luna flashes a warning. I read the forum for a solution and tried casting the converter and still the issues does not go away. When I execute the below code, I get a NullPointerException.
/**
* @return the filingMonth
*/
private ComboBox getFilingMonth() {
if (filingMonth == null) {
filingMonth = new ComboBox("Filing Month");
filingMonth.setWidth(FilingForm.FIELD_WIDTH);
filingMonth.setNullSelectionAllowed(false);
filingMonth.addItems(YearMonthUtil.getMonthNames());
filingMonth.setConverter((Converter) new MonthStringToInt());
}
return filingMonth;
}
Issue #2 - My data source (model) the filing month is an integer value. However, the combobox items (view) will display the month name. Since I cannot get the bean to register, I tried extending the combobox and and override the getValue() and setValue() mehtods. That didn't work out as well.
private void bindBeanToForm() {
if (binder == null) {
binder = new FieldGroup();
binder.setBuffered(true);
}
binder.setItemDataSource(new BeanItem<Filing>(this.filing));
binder.bind(filingMonth, "filingMonth");
}
Is my approach correct or am I not using Converter properly.
Thanks.
Hi,
I guess this article may help you: https://vaadin.com/wiki/-/wiki/Main/Creating+your+own+converter+for+String+-+MyType+conversion
The Book of Vaadin has some details that may be useful for you as well: https://vaadin.com/book/vaadin7/-/page/datamodel.properties.html
Thanks...I have already read both article. I can get the converters to work with textfield fine. However, I cannot get converters to work with comboboxes.