private <PT> BindingBuilder<T, PT> applyTextFieldNullValueRepresentationWorkaround(BindingBuilder<T, PT> bindingBuilder, Class<? extends FieldDefinition> definitionType) { //see https://github.com/vaadin/framework/issues/9619 if (TextFieldDefinition.class.isAssignableFrom(definitionType)) { bindingBuilder = (BindingBuilder<T, PT>) ((BindingBuilder<T, String>) bindingBuilder).withNullRepresentation(""); } return bindingBuilder; } }
@Override protected Component buildAndBindCustomComponent(String propertyId) { if ("id".equals(propertyId)) { TextField id = new TextField(getCaptionFromId(propertyId)); List<Validator> validators = getFieldFactory().getValidators(propertyId); Binder<SysConfig> binder = getBinder(); Binder.BindingBuilder builder = binder.forField(id) .asRequired(getApp().getMessage("errorMessage.req", StringUtils.capitalize(getCaptionFromId(propertyId)))) .withNullRepresentation("") .withConverter(userInputValue -> userInputValue , toPresentation -> removePrefix(toPresentation)); validators.forEach(builder::withValidator); builder.bind(propertyId); return id; } return null; }
RadioButtonGroup credit = createCreditOrDebit(); binder.forField(accountCode) .withNullRepresentation("") .withConverter(new AccountConverter()) .withValidator((Validator<Account>) (value, context) -> { .withConverter(new StringToBigDecimalConverter(app.getMessage("errorMessage.invalidAmount"))) .withValidator(new BigDecimalRangeValidator(app.getMessage("errorMessage.invalidAmount"), new BigDecimal("1"), new BigDecimal("99999999999999"))) .withNullRepresentation(BigDecimal.ZERO) .bind("amount"); binder.bind(credit, "credit");
TextField field = new TextField(getCaptionFromId(propertyId)); Binder.BindingBuilder<GLTransaction, String> builder = formatField(propertyId, field); builder.withNullRepresentation("").withConverter(new StringToTagConverter()).bind(propertyId); return field;