Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Invalid
-
8.0.0-M6
-
None
-
None
Description
I have a generic validator:
@Component public class UniqueFieldValidator implements ConstraintValidator<UniqueFieldValidator.UniqueField, String> { private AbstractEntityRepository<?,?> repository; private String fieldName; @Autowired private ApplicationContext applicationContext; @Target({ElementType.METHOD, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = UniqueFieldValidator.class) @Documented public @interface UniqueField { String fieldName(); Class<? extends AbstractEntityRepository<?,?>> repository(); String message() default "field.not.unique"; Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; } @Override public void initialize(UniqueField uniqueField) { this.repository = applicationContext.getBean(uniqueField.repository()); fieldName = uniqueField.fieldName(); } @Override public boolean isValid(String value, ConstraintValidatorContext ctx) { if(isBlank(value)){ return true; } Optional<?> o = repository.getOneByUniqueField(fieldName, value); return isFalse(o.isPresent()); } }
It works perfectly fine with SpringMVC Controllers, but when using Wicket's
new PropertyValidator<>()
field "repository" is null
Can you please take care that fields in Validators gets injected as well?