I have following code, but with converter field showing error "Must be a number", not "Own custom error text"
// crud instance
GridCrud<ExchangeRate> crud = new GridCrud<>(ExchangeRate.class);
...
// form configuration
DefaultCrudFormFactory<ExchangeRate> formFactory = (DefaultCrudFormFactory<ExchangeRate>) crud
.getCrudFormFactory();
...
// this code is not working
formFactory.setConverter("buyRate", new PriceConverter());
PriceConverter
public class PriceConverter implements Converter<String, BigDecimal> {
private final DecimalFormat df = FormattingUtils.getUiPriceFormatter();
@Override
public Result<BigDecimal> convertToModel(String presentationValue, ValueContext valueContext) {
try {
return Result.ok(new BigDecimal(presentationValue));
} catch (NumberFormatException e) {
return Result.error("Own custom error text");
}
}
@Override
public String convertToPresentation(BigDecimal modelValue, ValueContext valueContext) {
return convertIfNotNull(modelValue, i -> df.format(modelValue), () -> "");
}
}
Hello!
I have following code, but with converter field showing error "Must be a number", not "Own custom error text"
PriceConverter