You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Kamil (JIRA)" <ji...@apache.org> on 2017/05/29 12:07:04 UTC
[jira] [Created] (WICKET-6382) @Autowired in Validator doesn't work
with PropertyValidator
Kamil created WICKET-6382:
-----------------------------
Summary: @Autowired in Validator doesn't work with PropertyValidator
Key: WICKET-6382
URL: https://issues.apache.org/jira/browse/WICKET-6382
Project: Wicket
Issue Type: Bug
Components: wicket-bean-validation, wicket-spring
Affects Versions: 8.0.0-M6
Reporter: Kamil
I have a generic validator:
{code}
@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());
}
}
{code}
It works perfectly fine with SpringMVC Controllers, but when using Wicket's
{code}new PropertyValidator<>(){code} field "repository" is null
Can you please take care that fields in Validators gets injected as well?
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)