I want to bind a BigDecimal to a field in Vaadin, preferably a numberfield.
I tried this so far using a textfield with a converter and to bind it to a numberfield.
Could anyone provide information or an example on how to do this?
Here is a simple example of what I’m trying but failing to do:
If you want to use a NumberField for this, then you will have to implement a DoubleToBigDecimalConverter, as this is not provided by vaadin. Here is how it could look:
public class DoubleToBigDecimalConverter implements Converter<Double, BigDecimal> {
@Override
public Result<BigDecimal> convertToModel(Double presentation, ValueContext valueContext) {
return Result.ok(BigDecimal.valueOf(presentation));
}
@Override
public Double convertToPresentation(BigDecimal model, ValueContext valueContext) {
return model.doubleValue();
}
}
Now having this converter, you can bind your NumberField like so: