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/06/07 15:32:18 UTC
[jira] [Comment Edited] (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:comment-tabpanel&focusedCommentId=16040748#comment-16040748 ]
Kamil edited comment on WICKET-6382 at 6/7/17 3:31 PM:
-------------------------------------------------------
1)Run ./gradlew bootRun
2)Go to http://localhost:8080/createUser?login=NotOccupied&name=MyName&email=test@test.com and observe console -> User will be "created"
3)Go to http://localhost:8080/createUser?login=Occupied&name=MyName&email=test@test.com -> and observe console -> Validation error will be shown
4)Go to http://localhost:8080 click "Add user" and type Occupied, MyName, test@test.com. Click save and observe console -> Exception is thrown
If you are using IDEA - Enable Lombok plugin
was (Author: eximius):
1)Run ./gradlew bootRun
2)Go to http://localhost:8080/createUser?login=NotOccupied&name=MyName&email=test@test.com and observe console -> User will be "created"
3)Go to http://localhost:8080/createUser?login=Occupied&name=MyName&email=test@test.com -> and observe console -> Validation error will be shown
4)Go to http://localhost:8080 click "Add user" and type Occupied, MyName, test@test.com. Click save and observe console -> Exception is thrown
> @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
> 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)