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

Paul Speijers edited comment on WICKET-6344 at 3/24/17 7:21 AM:
----------------------------------------------------------------

Hi Martin. Unfortunately the pull request was a wrong way of creating an issue 
and I don't have a solution yet.

What I see in PropertyValidator.onConfigure is that now the following is only 
performed once to initially set the required flag, for instance on basis of a 
@NotNull constraint:
{code}
if (requiredFlagSet == false)
{
        // "Required" flag is calculated upon component's model property, so
        // we must ensure,
        // that model object is accessible (i.e. component is already added
        // in a page).
        requiredFlagSet = true;
        if (isRequired())
        {
                this.component.setRequired(true);
        }
}
{code}

What I do think is that when validation groups are dynamic it should be 
re-evaluated because the validation constraint @NotNull may not apply anymore.

However, my concern of this solution would be the case in which a component's 
required attribute has been set to false explicitly to true. The value set 
explicitly should never be overriden by such a re-evaluation. Maybe a potential 
solution for this would be to store the explicit decision in another boolean?


was (Author: paulspeijers):
Hi Martin. Unfortunately the pull request was a wrong way of creating an issue 
and I don't have a solution yet.

What I see in PropertyValidator.onConfigure is that now the following is only 
performed once to initially set the required flag, for instance on basis of a 
@NotNull constraint:
{code}
                if (requiredFlagSet == false)
                {
                        // "Required" flag is calculated upon component's model 
property, so
                        // we must ensure,
                        // that model object is accessible (i.e. component is 
already added
                        // in a page).
                        requiredFlagSet = true;
                        if (isRequired())
                        {
                                this.component.setRequired(true);
                        }
                }
{code}

What I do think is that when validation groups are dynamic it should be 
re-evaluated because the validation constraint @NotNull may not apply anymore.

However, my concern of this solution would be the case in which a component's 
required attribute has been set to false explicitly to true. The value set 
explicitly should never be overriden by such a re-evaluation. Maybe a potential 
solution for this would be to store the explicit decision in another boolean?

> 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