You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Adam Huječek <Hu...@seznam.cz> on 2015/01/28 11:22:35 UTC

PropertyValidator sets "Required" flag too late

Hello,
I am writing a simple stateless form with validation based on annotations in Wicket 7.0.0-SNAPSHOT. When the model's field is annotated @NotNull and PropertyValidator is added to its form component, the validation error is not generated if user's input is empty. It seems to me that the "Required" flag is set too late, because while debugging I noticed that isRequired is called at least once before PropertyValidator's onConfigure. In the end the component has the flag set but without effect. As a workaround I have created descendants of CheckBox, TextArea and TextField with isRequired overriden as follows:

    @Override
    public boolean isRequired() {
        if (!isRequiredRecurse) {
            isRequiredRecurse = true;
            configure(); //this should let PropertyValidator call setRequired
            isRequiredRecurse = false;
        }
        return super.isRequired();
    }

This fixes the problem, so it seems I configured everything correctly and also @Pattern works fine which leads me to think it's a bug, right? This may be related to issue WICKET-5329 "Required" flag initialized too early in PropertyValidator, which is the only ticket I found that could have any connection to this.

Sorry if this question has been already asked and answered. 

Thanks!
Adam
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: PropertyValidator sets "Required" flag too late

Posted by Adam Huječek <Hu...@seznam.cz>.
Ticket created, thank you for your time and explanation!

Adam


---------- Původní zpráva ----------
Od: Martin Grigorov <mg...@apache.org>
Komu: users@wicket.apache.org <us...@wicket.apache.org>
Datum: 28. 1. 2015 12:36:21
Předmět: Re: PropertyValidator sets "Required" flag too late

"Hi,

Yes. It is a bug. Please create a ticket.
The problem comes from the fact that you use stateless form. The required
flag is set for the form component on the rendered page, but later when the
form is submitted a new page with a new form (and components) is created
and the flag is gone.
Since there is no Behavior#onInitialize() we can only use #onBind() but as
WICKET-5329 says at this time the parent may be not yet available and the
logic breaks whenCompoundPropertyModel is used.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Wed, Jan 28, 2015 at 12:22 PM, Adam Huječek <Hu...@seznam.cz> wrote:

> Hello,
> I am writing a simple stateless form with validation based on annotations
> in Wicket 7.0.0-SNAPSHOT. When the model's field is annotated @NotNull and
> PropertyValidator is added to its form component, the validation error is
> not generated if user's input is empty. It seems to me that the "Required"
> flag is set too late, because while debugging I noticed that isRequired is
> called at least once before PropertyValidator's onConfigure. In the end 
the
> component has the flag set but without effect. As a workaround I have
> created descendants of CheckBox, TextArea and TextField with isRequired
> overriden as follows:
>
> @Override
> public boolean isRequired() {
> if (!isRequiredRecurse) {
> isRequiredRecurse = true;
> configure(); //this should let PropertyValidator call
> setRequired
> isRequiredRecurse = false;
> }
> return super.isRequired();
> }
>
> This fixes the problem, so it seems I configured everything correctly and
> also @Pattern works fine which leads me to think it's a bug, right? This
> may be related to issue WICKET-5329 "Required" flag initialized too early
> in PropertyValidator, which is the only ticket I found that could have any
> connection to this.
>
> Sorry if this question has been already asked and answered.
>
> Thanks!
> Adam
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>"

Re: PropertyValidator sets "Required" flag too late

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Yes. It is a bug. Please create a ticket.
The problem comes from the fact that you use stateless form. The required
flag is set for the form component on the rendered page, but later when the
form is submitted a new page with a new form (and components) is created
and the flag is gone.
Since there is no Behavior#onInitialize() we can only use #onBind() but as
WICKET-5329 says at this time the parent may be not yet available and the
logic breaks whenCompoundPropertyModel is used.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Wed, Jan 28, 2015 at 12:22 PM, Adam Huječek <Hu...@seznam.cz> wrote:

> Hello,
> I am writing a simple stateless form with validation based on annotations
> in Wicket 7.0.0-SNAPSHOT. When the model's field is annotated @NotNull and
> PropertyValidator is added to its form component, the validation error is
> not generated if user's input is empty. It seems to me that the "Required"
> flag is set too late, because while debugging I noticed that isRequired is
> called at least once before PropertyValidator's onConfigure. In the end the
> component has the flag set but without effect. As a workaround I have
> created descendants of CheckBox, TextArea and TextField with isRequired
> overriden as follows:
>
>     @Override
>     public boolean isRequired() {
>         if (!isRequiredRecurse) {
>             isRequiredRecurse = true;
>             configure(); //this should let PropertyValidator call
> setRequired
>             isRequiredRecurse = false;
>         }
>         return super.isRequired();
>     }
>
> This fixes the problem, so it seems I configured everything correctly and
> also @Pattern works fine which leads me to think it's a bug, right? This
> may be related to issue WICKET-5329 "Required" flag initialized too early
> in PropertyValidator, which is the only ticket I found that could have any
> connection to this.
>
> Sorry if this question has been already asked and answered.
>
> Thanks!
> Adam
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>