I have an object that accepts port numbers (get/set) I created a DoubleToIntegerConverter in order to use the NumberField to bind to an int (set/get at the object).
public class DoubleToIntegerConverter implements Converter<Double, Integer> {
private static final long serialVersionUID = 1L;
@Override
public Result<Integer> convertToModel(Double presentation, ValueContext valueContext) {
return Result.ok(presentation.intValue());
}
@Override
public Double convertToPresentation(Integer model, ValueContext valueContext) {
return model.doubleValue();
}
}
The problem I have now is that when I set the value of the field through the binder, i.e. for a port number it shows 443.0 instead of 443 (integer value).
Is there a way to have the numberfield discard the decimal places?
reportPortField.setStep(1);
reportPortField.setMin(1);
reportPortField.setMax(65535);
and
binder.forField(reportPortField).asRequired().withConverter(new DoubleToIntegerConverter()).bind(ServerObject::getReportPort, ServerObject::setReportPort);
None of the above did the trick!
Thanks!!