FieldFactoryImpl implements FieldFactory { @SuppressWarnings("unchecked") public <U, V> void addConvertersAndValidators(BindingBuilder<U, V> builder, AttributeModel am, Converter<V, U> customConverter, Validator<V> customValidator, Validator<V> customRequiredValidator) { if (customValidator != null) { builder.withValidator(customValidator); } if (customConverter != null) { builder.withConverter(customConverter); } if (customRequiredValidator != null) { builder.asRequired(customRequiredValidator); } if (am.isEmail()) { BindingBuilder<U, String> sBuilder = (BindingBuilder<U, String>) builder; sBuilder.withNullRepresentation("").withValidator( new EmailValidator(messageService.getMessage("ocs.no.valid.email", VaadinUtils.getLocale()))); } else if (am.isWeek()) { BindingBuilder<U, String> sBuilder = (BindingBuilder<U, String>) builder; sBuilder.withConverter(new LocalDateWeekCodeConverter()); } else if (builder.getField() instanceof TextField) { BindingBuilder<U, String> sBuilder = (BindingBuilder<U, String>) builder; sBuilder.withNullRepresentation(""); if (customConverter == null) { if (am.getType().equals(BigDecimal.class)) { sBuilder.withConverter(ConverterFactory.createBigDecimalConverter(am.isCurrency(), am.isPercentage(), SystemPropertyUtils.useThousandsGroupingInEditMode(), am.getPrecision(), VaadinUtils.getCurrencySymbol())); } else if (NumberUtils.isInteger(am.getType())) { sBuilder.withConverter(ConverterFactory.createIntegerConverter( SystemPropertyUtils.useThousandsGroupingInEditMode(), am.isPercentage())); } else if (NumberUtils.isLong(am.getType())) { sBuilder.withConverter(ConverterFactory.createLongConverter( SystemPropertyUtils.useThousandsGroupingInEditMode(), am.isPercentage())); } else if (NumberUtils.isDouble(am.getType())) { sBuilder.withConverter(ConverterFactory.createDoubleConverter(am.isCurrency(), SystemPropertyUtils.useThousandsGroupingInEditMode(), am.isPercentage(), am.getPrecision(), VaadinUtils.getCurrencySymbol())); } } } else if (builder.getField() instanceof URLField) { BindingBuilder<U, String> sBuilder = (BindingBuilder<U, String>) builder; sBuilder.withNullRepresentation("").withValidator( new URLValidator(messageService.getMessage("ocs.no.valid.url", VaadinUtils.getLocale()))); } } FieldFactoryImpl();  FieldFactoryImpl(FieldFactory delegate); @SuppressWarnings("unchecked") void addConvertersAndValidators(BindingBuilder<U, V> builder, AttributeModel am,
			Converter<V, U> customConverter, Validator<V> customValidator, Validator<V> customRequiredValidator); @Override Component constructField(AttributeModel am); Component constructField(FieldFactoryContext context); @SuppressWarnings("unchecked") Component constructInternalLinkField(
			AttributeModel am, EntityModel<?> entityModel);  }
@Test public void testEmail() { Component ac = constructField2("email", false, false); assertTrue(ac instanceof TextField); TextField tf = (TextField) ac; Binder<TestEntity2> binder = new BeanValidationBinder<>(TestEntity2.class); TestEntity2 t2 = new TestEntity2(); binder.setBean(t2); EntityModel<TestEntity2> em = factory.getModel(TestEntity2.class); fieldFactory.addConvertersAndValidators(binder.forField(tf), em.getAttributeModel("email"), null, null, null); }