.withValidator(field.getDefaultValidator());
protected Component buildAndBindCustomComponent(String propertyId) { if ("roles".equals(propertyId)) { CheckBoxGroup g = new CheckBoxGroup(StringUtils.capitalize(getCaptionFromId(propertyId))); g.setItems(((UsersHelper)getHelper()).getRoles()); g.setItemCaptionGenerator((ItemCaptionGenerator<Role>) item -> StringUtils.capitalize(item.getName())); List<Validator> v = getFieldFactory().getValidators(propertyId); Binder.BindingBuilder builder = getBinder().forField(g); for (Validator val : v) { builder.withValidator(val); } builder.bind(propertyId); return g; } return null; }
@SuppressWarnings({ "unchecked", "rawtypes" }) private void setEditorBinding(P property, Column column, HasValue editor, boolean readOnly, PropertyColumn<?, ?> pc) { BindingBuilder builder = getGrid().getEditor().getBinder().forField(editor); if (pc.isRequired()) { final Localizable requiredMessage = (pc.getRequiredMessage() != null) ? pc.getRequiredMessage() : RequiredInputValidator.DEFAULT_REQUIRED_ERROR; builder.asRequired(context -> { return LocalizationContext.translate(requiredMessage, true); }); } // default validators getDefaultPropertyValidators(property).forEach(v -> builder.withValidator(new ValidatorWrapper<>(v))); // validators pc.getValidators().forEach(v -> builder.withValidator(v)); // bind column.setEditorBinding(builder.bind(getColumnId(property))); // set editable if not read-only column.setEditable(!readOnly); }
.withNullRepresentation("") .withConverter(new AccountConverter()) .withValidator((Validator<Account>) (value, context) -> { if (value!=null && !(value instanceof FinalAccount)) return ValidationResult.error(app.getMessage("errorMessage.accountNotFinal")); .bind("layer"); binder.forField(detail) .withValidator(new StringLengthValidator(app.getMessage("errorMessage.invalidField", detail.getCaption()), 0, 255)) .withValidator(new RegexpValidator(app.getMessage("errorMessage.invalidField", detail.getCaption()), TEXT_REGEX)) .bind("detail"); binder.forField(tags) .withValidator(new StringLengthValidator(app.getMessage("errorMessage.invalidField", tags.getCaption()), 0, 255)) .withValidator(new RegexpValidator(app.getMessage("errorMessage.invalidField", tags.getCaption()), TEXT_REGEX)) .withConverter(new StringToTagConverter()) .bind("tags"); .asRequired(app.getMessage("errorMessage.req", StringUtils.capitalize(amount.getCaption()))) .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");
.withValidator(((UsersHelper)getHelper()).getCurrentPasswordMatchValidator()) .bind(string->string,null); form.addComponent(currentPasswordField); passwordBinder.forField(newPasswordField) .asRequired(getApp().getMessage("errorMessage.req",newPasswordField.getCaption())) .withValidator(((UsersHelper)getHelper()).getNewPasswordNotUsedValidator()) .bind(string->string,null); form.addComponent(newPasswordField); passwordBinder.forField(repeatPasswordField) .asRequired(getApp().getMessage("errorMessage.req", repeatPasswordField.getCaption())) .withValidator(((UsersHelper)getHelper()).getPasswordsMatchValidator(newPasswordField)) .bind(string->string,null); form.addComponent(repeatPasswordField);
SerializablePredicate<? super TARGET> predicate, String message, ErrorLevel errorLevel) { return withValidator( Validator.from(predicate, message, errorLevel));
ErrorMessageProvider errorMessageProvider, ErrorLevel errorLevel) { return withValidator(Validator.from(predicate, errorMessageProvider, errorLevel));
/** * A convenience method to add a validator to this binding using the * {@link Validator#from(SerializablePredicate, String)} factory method. * <p> * Validators are applied, in registration order, when the field value * is written to the backing property. If any validator returns a * failure, the property value is not updated. * * @see #withValidator(Validator) * @see #withValidator(SerializablePredicate, String, ErrorLevel) * @see #withValidator(SerializablePredicate, ErrorMessageProvider) * @see Validator#from(SerializablePredicate, String) * * @param predicate * the predicate performing validation, not null * @param message * the error message to report in case validation failure * @return this binding, for chaining * @throws IllegalStateException * if {@code bind} has already been called */ public default BindingBuilder<BEAN, TARGET> withValidator( SerializablePredicate<? super TARGET> predicate, String message) { return withValidator(Validator.from(predicate, message)); }
/** * A convenience method to add a validator to this binding using the * {@link Validator#from(SerializablePredicate, ErrorMessageProvider)} * factory method. * <p> * Validators are applied, in registration order, when the field value * is written to the backing property. If any validator returns a * failure, the property value is not updated. * * @see #withValidator(Validator) * @see #withValidator(SerializablePredicate, String) * @see #withValidator(SerializablePredicate, ErrorMessageProvider, * ErrorLevel) * @see Validator#from(SerializablePredicate, ErrorMessageProvider) * * @param predicate * the predicate performing validation, not null * @param errorMessageProvider * the provider to generate error messages, not null * @return this binding, for chaining * @throws IllegalStateException * if {@code bind} has already been called */ public default BindingBuilder<BEAN, TARGET> withValidator( SerializablePredicate<? super TARGET> predicate, ErrorMessageProvider errorMessageProvider) { return withValidator( Validator.from(predicate, errorMessageProvider)); }
@Override protected BindingBuilder<BEAN, ?> configureBinding( BindingBuilder<BEAN, ?> binding, PropertyDefinition<BEAN, ?> definition) { Class<?> actualBeanType = findBeanType(beanType, definition); BeanValidator validator = new BeanValidator(actualBeanType, definition.getTopLevelName()); if (requiredConfigurator != null) { configureRequired(binding, definition, validator); } return binding.withValidator(validator); }