private void configureRequired(BindingBuilder<BEAN, ?> binding, PropertyDefinition<BEAN, ?> definition, BeanValidator validator) { assert requiredConfigurator != null; Class<?> propertyHolderType = definition.getPropertyHolderType(); BeanDescriptor descriptor = validator.getJavaxBeanValidator() .getConstraintsForClass(propertyHolderType); PropertyDescriptor propertyDescriptor = descriptor .getConstraintsForProperty(definition.getTopLevelName()); if (propertyDescriptor == null) { return; } if (propertyDescriptor.getConstraintDescriptors().stream() .map(ConstraintDescriptor::getAnnotation) .anyMatch(requiredConfigurator)) { binding.getField().setRequiredIndicatorVisible(true); } }
public <PT> BindingBuilder<T, PT> applyConfiguration(BindingBuilder<T, PT> bindingBuilder, FieldDefinition<PT> definition, Object... parameters) { if (definition.isRequired()) { bindingBuilder.asRequired(definition.getRequiredErrorMessage()); } bindingBuilder = definition.getValidators().stream() .map(this::newValidator) .reduce(bindingBuilder, BindingBuilder::withValidator, defaultCombiner()); final Converter converter = newConverter(definition, bindingBuilder.getField(), parameters); if (converter != null) { bindingBuilder = bindingBuilder.withConverter(converter); final Class<? extends FieldDefinition> definitionType = definition.getClass(); bindingBuilder = applyTextFieldNullValueRepresentationWorkaround(bindingBuilder, definitionType); } final PT fieldValue = (PT) bindingBuilder.getField().getValue(); if (converter == null && fieldValue != null && !definition.getType().isInstance(fieldValue)) { log.warn(String.format("Type mismatch for field named [%s]. Configured type is [%s] but bound component value type is [%s] and no suitable converter has been found. Please check your configuration.", definition.getName(), definition.getType(), fieldValue.getClass())); } Optional.ofNullable(definition.getDefaultValue()).ifPresent(bindingBuilder::withNullRepresentation); return bindingBuilder; }