Null value is not supported - Vaadin Flow 14

In Vaadi8 I used fields, testing the null value to evaluate if it was undefined.
Now, in Vaadin 14, a textfield has allways a value (e.g. “”).
If I try to set it null I get “Null value is not supported”.
Is it possible to manage/allows null value in fields ?

You’d have to write your own TextField component. There’s no “allow null values” method. As a work around, I just use a converter because I don’t want empty strings in the database.

public class TextfieldConverter implements Converter<String, String> {
    public Result<String> convertToModel(String text, ValueContext context) {
        return Result.ok(text.equals("") ? null : text);
    public String convertToPresentation(String text, ValueContext context) {
        return text != null ? text : "";

Two questions.
First why ? it seems to me stupid.
Second where should I declare the converter ?

I’m afraid I can’t answer the why. If I know I’m not going to use the converter anywhere else, I make it a private class inside the class that uses it. Otherwise, I have a separate package where it’s a stand alone class.
See the Vaadin documentation for how to use a Binder.

You can define a nullValueRepresentation on the binding of the TextField (or any other HasValue) to a Binder. This will allow a null value for the textfield, but you will have to define what actual value is shown in that case (you could use “” for example, or “-”).

TextField tf = new TextField("foo");
	.bind(FooBar::getFoo, FooBar::setFoo);