I’m basically following a tutorial on setting up CRUD editor form from a grid of the table results. Everything works with creating TextFields for Strings, but then it throws an IllegalStateException when trying to bind to an element that is an Integer type. (If I simply comment out that one field from the editor form, everything works as expected.) I’m using vaadin-bom 8.0.0.
I have an editor class:
[code]
public class ItemEditor extends VerticalLayout {
…
TextField itemCount = new TextField(“ItemCount”);
…
Binder binder = new Binder<>(Item.class);
addComponents(itemCount, …);
binder.bindInstanceFields(this);
//Throwing exception!
[/code]
Where Item has an Integer field itemCount;
public class Item {
private Integer itemCount;
...
}
So I look around and find that I have to manually set up a binder for non-string items to TextField,
even for the basic primitave types.
OK, no big deal, so I then manually add this:
[code]
…
binder.forField(itemCount)
.withConverter(new StringToIntegerConverter(“”))
//.withConverter(Integer::valueOf, String::valueOf)
.bind(Item::getItemCount, Item::setItemCount);
addComponents(itemCount, …);
binder.bindInstanceFields(this); //Still throwing exception on the itemCount field!
…
[/code]
Results in:
java.lang.IllegalStateException: Property type ‘java.lang.Integer’ doesn’t match the field type ‘java.lang.String’. Binding should be configured manually using converter.
Quote from the documentation:
[code]
We can also bind some of the fields before calling bindInstanceFields. In this way, fields that require special configuration can still be configured manually while regular fields can be configured automatically.
binder.forField(yearOfBirth)
.withConverter(
new StringToIntegerConverter(“Please enter a number”))
.bind(Person::getYearOfBirth, Person::setYearOfBirth));
binder.bindInstanceFields(this);
[/code]
But I am binding it manually…
What gives!?