Loading...
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.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Vaadin 8 Binder

Kareem Jabr
5 years ago Mar 24, 2017 5:29am
Johannes Häyry
5 years ago Mar 24, 2017 7:09am
Kareem Jabr
5 years ago Mar 24, 2017 4:21pm
Nicklas Karlsson
5 years ago Mar 28, 2017 5:51am
Martin Vyšný
4 years ago Jun 24, 2017 5:54pm
Ilia Motornyi
4 years ago Jul 24, 2017 10:14am
C. Berg
4 years ago Aug 11, 2017 2:17pm
Ulrich Maurer
4 years ago Aug 23, 2017 8:11am

I had the same NPE issue with StringToBigDecimalConverter.
The solution of C.Berg doesn't work for me because it doesn't handle numbers in non english format.
The workaround of Martin Vyšný (https://github.com/vaadin/framework/issues/8664) is the best solution because it uses a NumberFormat with the current locale.

In your case it would look as follows:

binder.forField(price)
    .withNullRepresentation("")
    .withConverter(new StringToBigDecimalConverter("Price must be in ##.## format"))
    .bind(Item::getPrice, Item::setPrice);

This results in an empty field, if the price is null and returns null, if the field is empty.