You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Sven Meier (JIRA)" <ji...@apache.org> on 2017/06/08 19:15:18 UTC
[jira] [Resolved] (WICKET-6382) @Autowired in Validator doesn't
work with PropertyValidator
[ https://issues.apache.org/jira/browse/WICKET-6382?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sven Meier resolved WICKET-6382.
--------------------------------
Resolution: Invalid
This is a problem in your wicket-spring-boot integration.
> @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
> Assignee: Sven Meier
> Attachments: wicket-showcase-validatorAutowire.zip
>
>
> 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)