[ 
https://issues.apache.org/jira/browse/WICKET-6344?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15938677#comment-15938677
 ] 

Martin Grigorov commented on WICKET-6344:
-----------------------------------------

Could you please provide a quickstart that demonstrates the issue ?
You also tried to create a Pull Request recently but it was against the wrong 
target branch. If you know how to fix this we will be glad to apply a patch or 
guide you how to create a Pull Request!
Thank you!

> PropertyValidator does not work with dynamic validation groups
> --------------------------------------------------------------
>
>                 Key: WICKET-6344
>                 URL: https://issues.apache.org/jira/browse/WICKET-6344
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket-bean-validation
>    Affects Versions: 7.4.0
>            Reporter: Paul Speijers
>
> The Wicket property validator does not work with dynamic validation groups 
> because of the following issues:
> # It can not cope with the case in which the Default validation group is 
> provided explicitly
> # The initial validation groups determine whether required should be set on 
> the component. But the PropertyValidator never unsets the flag.
> When using a Wicket property validator you can provide a model for the 
> validation groups:
> {code}
> IModel<Class<?>[]> validationGroups = Model.of(new Class[]{Default.class});
> new PropertyValidator<>(validationGroups);
> {code}
> Let's say I have the following model object:
> {code}
> public class MyObject {
>     @NotNull
>     private String name;
>     
>     @NotNull(groups=AdditionalValidations.class)
>     private String additional;
> }
> {code}
> Then the @NotNull constraint on the name attribute is NOT performed when 
> submitting the form.
> This is caused by the fact that no validations are performed within 
> FormComponent.validateValidators. On the following line both conditions 
> evaluate to false:
> {code}
> if (isNull == false || validator instanceof INullAcceptingValidator<?>)
> {code}
> The trick to perform "required" validations is that the PropertyValidator 
> sets the component to required within its onConfigure method:
> {code}
> this.component.setRequired(true);
> {code}
> However, this is only performed when isRequired() evaluates to true, which is 
> NOT the case in my example. This is related to issue 1:
> When the Default validation group is provided explicitly, isRequired returns 
> the wrong result.
> Issue 2 has to do with the required flag only being set once by the 
> PropertyValidator:
> Given the example model object above. Assume that when I create the form 
> components I don't set them required explicitly 
> (formComponent.setRequired(true), but I rather let it up to the 
> PropertyValidator because I want to describe my validations on one place, the 
> model object. So, when I initially create the PropertyValidator the 
> "additional" model object attribute is NOT set to required within 
> PropertyValidator.onConfigure, because the validation groups don't match. 
> Then when I would dynamically change the validation groups:
> {code}
> validationGroups.setObject(new Class[]{Default.class, 
> AdditionalValidations.class});
> {code}
> Then subsequently a required/NotNull validation should be performed for the 
> "additional" attribute when submitting the form. However, it is not performed 
> because within PropertyValidator.onConfigure it is only set to required once, 
> and not updated at a later stage.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to