Quantcast

INullAcceptingValidator behavior

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

INullAcceptingValidator behavior

akarypid
Hello,

1) I have a custom validator that implements INullAcceptingValidator.
2) A TextField component in my form has validator (1) attached to it and  
is setRequired(false).
3) When I submit my form with the text input empty, the validator does NOT  
get called. It only gets called if there is a value with the HTML input  
field.

I was expecting that the validator would be invoked upon submission even  
if the text field is empty, in order to validate tha value "null". At  
least this is what I understand as far as INullAcceptingValidator goes.  
However, this does not appear to happen. Instead, Wicket goes on to call  
the form's onSubmit() method with the value "null" inside my model.

What am I missing?

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: INullAcceptingValidator behavior

Martin Grigorov-4
Maybe org.apache.wicket.markup.html.form.FormComponent.isInputNullable()
which is overridden by
org.apache.wicket.markup.html.form.AbstractTextComponent.isInputNullable()

On Fri, Jun 3, 2011 at 12:00 PM, Alexandros Karypidis <[hidden email]> wrote:

> Hello,
>
> 1) I have a custom validator that implements INullAcceptingValidator.
> 2) A TextField component in my form has validator (1) attached to it and is
> setRequired(false).
> 3) When I submit my form with the text input empty, the validator does NOT
> get called. It only gets called if there is a value with the HTML input
> field.
>
> I was expecting that the validator would be invoked upon submission even if
> the text field is empty, in order to validate tha value "null". At least
> this is what I understand as far as INullAcceptingValidator goes. However,
> this does not appear to happen. Instead, Wicket goes on to call the form's
> onSubmit() method with the value "null" inside my model.
>
> What am I missing?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: INullAcceptingValidator behavior

akarypid
Hello again,

I'm in a weird place. I've stepped through the code and located my problem  
in:

http://svn.apache.org/repos/asf/wicket/releases/wicket-1.5-RC4.2/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java

At line 1383, the method "validateValidators()" visits all validators.  
While iterating, it reaches my validator BUT decides to skip it because of  
the check on line 1398:

if (isNull == false || validator instanceof INullAcceptingValidator<?>)

The problem is that my validator is "wrapped" by class "ValidatorAdapter":

http://svn.apache.org/repos/asf/wicket/releases/wicket-1.5-RC4.2/wicket-core/src/main/java/org/apache/wicket/validation/ValidatorAdapter.java

As you can see, this class implements IValidator<T> and therefore the  
check fails, even though the value of the "wrapped" validator is in fact  
an instance of INullAcceptingValidator.

I would have got the expected behavior if the check was written as:

if (isNull == false
        || validator instanceof INullAcceptingValidator<?>
        || (
                // wicket should check against the actual validator:
                validator instanceof ValidatorAdapter<T> &&
                validator.getValidator() iinstanceof INullAcceptingValidator<?>)
       )

Could this be a bug?

On Fri, 03 Jun 2011 12:05:46 +0300, Martin Grigorov <[hidden email]>  
wrote:

> Maybe org.apache.wicket.markup.html.form.FormComponent.isInputNullable()
> which is overridden by
> org.apache.wicket.markup.html.form.AbstractTextComponent.isInputNullable()
>
> On Fri, Jun 3, 2011 at 12:00 PM, Alexandros Karypidis  
> <[hidden email]> wrote:
>> Hello,
>>
>> 1) I have a custom validator that implements INullAcceptingValidator.
>> 2) A TextField component in my form has validator (1) attached to it  
>> and is
>> setRequired(false).
>> 3) When I submit my form with the text input empty, the validator does  
>> NOT
>> get called. It only gets called if there is a value with the HTML input
>> field.
>>
>> I was expecting that the validator would be invoked upon submission  
>> even if
>> the text field is empty, in order to validate tha value "null". At least
>> this is what I understand as far as INullAcceptingValidator goes.  
>> However,
>> this does not appear to happen. Instead, Wicket goes on to call the  
>> form's
>> onSubmit() method with the value "null" inside my model.
>>
>> What am I missing?
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: INullAcceptingValidator behavior

Martin Grigorov-4
Yes. It looks like a bug

On Fri, Jun 3, 2011 at 12:47 PM, Alexandros Karypidis <[hidden email]> wrote:

> Hello again,
>
> I'm in a weird place. I've stepped through the code and located my problem
> in:
>
> http://svn.apache.org/repos/asf/wicket/releases/wicket-1.5-RC4.2/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
>
> At line 1383, the method "validateValidators()" visits all validators. While
> iterating, it reaches my validator BUT decides to skip it because of the
> check on line 1398:
>
> if (isNull == false || validator instanceof INullAcceptingValidator<?>)
>
> The problem is that my validator is "wrapped" by class "ValidatorAdapter":
>
> http://svn.apache.org/repos/asf/wicket/releases/wicket-1.5-RC4.2/wicket-core/src/main/java/org/apache/wicket/validation/ValidatorAdapter.java
>
> As you can see, this class implements IValidator<T> and therefore the check
> fails, even though the value of the "wrapped" validator is in fact an
> instance of INullAcceptingValidator.
>
> I would have got the expected behavior if the check was written as:
>
> if (isNull == false
>        || validator instanceof INullAcceptingValidator<?>
>        || (
>                // wicket should check against the actual validator:
>                validator instanceof ValidatorAdapter<T> &&
>                validator.getValidator() iinstanceof
> INullAcceptingValidator<?>)
>      )
>
> Could this be a bug?
>
> On Fri, 03 Jun 2011 12:05:46 +0300, Martin Grigorov <[hidden email]>
> wrote:
>
>> Maybe org.apache.wicket.markup.html.form.FormComponent.isInputNullable()
>> which is overridden by
>> org.apache.wicket.markup.html.form.AbstractTextComponent.isInputNullable()
>>
>> On Fri, Jun 3, 2011 at 12:00 PM, Alexandros Karypidis <[hidden email]>
>> wrote:
>>>
>>> Hello,
>>>
>>> 1) I have a custom validator that implements INullAcceptingValidator.
>>> 2) A TextField component in my form has validator (1) attached to it and
>>> is
>>> setRequired(false).
>>> 3) When I submit my form with the text input empty, the validator does
>>> NOT
>>> get called. It only gets called if there is a value with the HTML input
>>> field.
>>>
>>> I was expecting that the validator would be invoked upon submission even
>>> if
>>> the text field is empty, in order to validate tha value "null". At least
>>> this is what I understand as far as INullAcceptingValidator goes.
>>> However,
>>> this does not appear to happen. Instead, Wicket goes on to call the
>>> form's
>>> onSubmit() method with the value "null" inside my model.
>>>
>>> What am I missing?
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: INullAcceptingValidator behavior

akarypid
In reply to this post by akarypid
BTW, I just located where the adapter is instantiated. Again, in:

http://svn.apache.org/repos/asf/wicket/releases/wicket-1.5-RC4.2/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java

You will find in line 465:

        add((Behavior)new ValidatorAdapter(validator));

I really can't see how my INullAcceptingValidator could ever get a chance  
to process a null value, unless the check of "validateValidators()" is  
changed...

On Fri, 03 Jun 2011 12:47:57 +0300, Alexandros Karypidis  
<[hidden email]> wrote:

> Hello again,
>
> I'm in a weird place. I've stepped through the code and located my  
> problem in:
>
> http://svn.apache.org/repos/asf/wicket/releases/wicket-1.5-RC4.2/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
>
> At line 1383, the method "validateValidators()" visits all validators.  
> While iterating, it reaches my validator BUT decides to skip it because  
> of the check on line 1398:
>
> if (isNull == false || validator instanceof INullAcceptingValidator<?>)
>
> The problem is that my validator is "wrapped" by class  
> "ValidatorAdapter":
>
> http://svn.apache.org/repos/asf/wicket/releases/wicket-1.5-RC4.2/wicket-core/src/main/java/org/apache/wicket/validation/ValidatorAdapter.java
>
> As you can see, this class implements IValidator<T> and therefore the  
> check fails, even though the value of the "wrapped" validator is in fact  
> an instance of INullAcceptingValidator.
>
> I would have got the expected behavior if the check was written as:
>
> if (isNull == false
> || validator instanceof INullAcceptingValidator<?>
> || (
> // wicket should check against the actual validator:
> validator instanceof ValidatorAdapter<T> &&
> validator.getValidator() iinstanceof INullAcceptingValidator<?>)
>        )
>
> Could this be a bug?
>
> On Fri, 03 Jun 2011 12:05:46 +0300, Martin Grigorov  
> <[hidden email]> wrote:
>
>> Maybe org.apache.wicket.markup.html.form.FormComponent.isInputNullable()
>> which is overridden by
>> org.apache.wicket.markup.html.form.AbstractTextComponent.isInputNullable()
>>
>> On Fri, Jun 3, 2011 at 12:00 PM, Alexandros Karypidis  
>> <[hidden email]> wrote:
>>> Hello,
>>>
>>> 1) I have a custom validator that implements INullAcceptingValidator.
>>> 2) A TextField component in my form has validator (1) attached to it  
>>> and is
>>> setRequired(false).
>>> 3) When I submit my form with the text input empty, the validator does  
>>> NOT
>>> get called. It only gets called if there is a value with the HTML input
>>> field.
>>>
>>> I was expecting that the validator would be invoked upon submission  
>>> even if
>>> the text field is empty, in order to validate tha value "null". At  
>>> least
>>> this is what I understand as far as INullAcceptingValidator goes.  
>>> However,
>>> this does not appear to happen. Instead, Wicket goes on to call the  
>>> form's
>>> onSubmit() method with the value "null" inside my model.
>>>
>>> What am I missing?
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: INullAcceptingValidator behavior

akarypid
In reply to this post by Martin Grigorov-4
Ok, I'll open a JIRA and refer to this thread. Fix seems easy enough.

On Fri, 03 Jun 2011 12:50:40 +0300, Martin Grigorov <[hidden email]>  
wrote:

> Yes. It looks like a bug
>
> On Fri, Jun 3, 2011 at 12:47 PM, Alexandros Karypidis  
> <[hidden email]> wrote:
>> Hello again,
>>
>> I'm in a weird place. I've stepped through the code and located my  
>> problem
>> in:
>>
>> http://svn.apache.org/repos/asf/wicket/releases/wicket-1.5-RC4.2/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
>>
>> At line 1383, the method "validateValidators()" visits all validators.  
>> While
>> iterating, it reaches my validator BUT decides to skip it because of the
>> check on line 1398:
>>
>> if (isNull == false || validator instanceof INullAcceptingValidator<?>)
>>
>> The problem is that my validator is "wrapped" by class  
>> "ValidatorAdapter":
>>
>> http://svn.apache.org/repos/asf/wicket/releases/wicket-1.5-RC4.2/wicket-core/src/main/java/org/apache/wicket/validation/ValidatorAdapter.java
>>
>> As you can see, this class implements IValidator<T> and therefore the  
>> check
>> fails, even though the value of the "wrapped" validator is in fact an
>> instance of INullAcceptingValidator.
>>
>> I would have got the expected behavior if the check was written as:
>>
>> if (isNull == false
>>        || validator instanceof INullAcceptingValidator<?>
>>        || (
>>                // wicket should check against the actual validator:
>>                validator instanceof ValidatorAdapter<T> &&
>>                validator.getValidator() iinstanceof
>> INullAcceptingValidator<?>)
>>      )
>>
>> Could this be a bug?
>>
>> On Fri, 03 Jun 2011 12:05:46 +0300, Martin Grigorov  
>> <[hidden email]>
>> wrote:
>>
>>> Maybe  
>>> org.apache.wicket.markup.html.form.FormComponent.isInputNullable()
>>> which is overridden by
>>> org.apache.wicket.markup.html.form.AbstractTextComponent.isInputNullable()
>>>
>>> On Fri, Jun 3, 2011 at 12:00 PM, Alexandros Karypidis  
>>> <[hidden email]>
>>> wrote:
>>>>
>>>> Hello,
>>>>
>>>> 1) I have a custom validator that implements INullAcceptingValidator.
>>>> 2) A TextField component in my form has validator (1) attached to it  
>>>> and
>>>> is
>>>> setRequired(false).
>>>> 3) When I submit my form with the text input empty, the validator does
>>>> NOT
>>>> get called. It only gets called if there is a value with the HTML  
>>>> input
>>>> field.
>>>>
>>>> I was expecting that the validator would be invoked upon submission  
>>>> even
>>>> if
>>>> the text field is empty, in order to validate tha value "null". At  
>>>> least
>>>> this is what I understand as far as INullAcceptingValidator goes.
>>>> However,
>>>> this does not appear to happen. Instead, Wicket goes on to call the
>>>> form's
>>>> onSubmit() method with the value "null" inside my model.
>>>>
>>>> What am I missing?
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: INullAcceptingValidator behavior

akarypid
https://issues.apache.org/jira/browse/WICKET-3767

On Fri, 03 Jun 2011 12:56:06 +0300, Alexandros Karypidis  
<[hidden email]> wrote:

> Ok, I'll open a JIRA and refer to this thread. Fix seems easy enough.
>
> On Fri, 03 Jun 2011 12:50:40 +0300, Martin Grigorov  
> <[hidden email]> wrote:
>
>> Yes. It looks like a bug
>>
>> On Fri, Jun 3, 2011 at 12:47 PM, Alexandros Karypidis  
>> <[hidden email]> wrote:
>>> Hello again,
>>>
>>> I'm in a weird place. I've stepped through the code and located my  
>>> problem
>>> in:
>>>
>>> http://svn.apache.org/repos/asf/wicket/releases/wicket-1.5-RC4.2/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
>>>
>>> At line 1383, the method "validateValidators()" visits all validators.  
>>> While
>>> iterating, it reaches my validator BUT decides to skip it because of  
>>> the
>>> check on line 1398:
>>>
>>> if (isNull == false || validator instanceof INullAcceptingValidator<?>)
>>>
>>> The problem is that my validator is "wrapped" by class  
>>> "ValidatorAdapter":
>>>
>>> http://svn.apache.org/repos/asf/wicket/releases/wicket-1.5-RC4.2/wicket-core/src/main/java/org/apache/wicket/validation/ValidatorAdapter.java
>>>
>>> As you can see, this class implements IValidator<T> and therefore the  
>>> check
>>> fails, even though the value of the "wrapped" validator is in fact an
>>> instance of INullAcceptingValidator.
>>>
>>> I would have got the expected behavior if the check was written as:
>>>
>>> if (isNull == false
>>>        || validator instanceof INullAcceptingValidator<?>
>>>        || (
>>>                // wicket should check against the actual validator:
>>>                validator instanceof ValidatorAdapter<T> &&
>>>                validator.getValidator() iinstanceof
>>> INullAcceptingValidator<?>)
>>>      )
>>>
>>> Could this be a bug?
>>>
>>> On Fri, 03 Jun 2011 12:05:46 +0300, Martin Grigorov  
>>> <[hidden email]>
>>> wrote:
>>>
>>>> Maybe  
>>>> org.apache.wicket.markup.html.form.FormComponent.isInputNullable()
>>>> which is overridden by
>>>> org.apache.wicket.markup.html.form.AbstractTextComponent.isInputNullable()
>>>>
>>>> On Fri, Jun 3, 2011 at 12:00 PM, Alexandros Karypidis  
>>>> <[hidden email]>
>>>> wrote:
>>>>>
>>>>> Hello,
>>>>>
>>>>> 1) I have a custom validator that implements INullAcceptingValidator.
>>>>> 2) A TextField component in my form has validator (1) attached to it  
>>>>> and
>>>>> is
>>>>> setRequired(false).
>>>>> 3) When I submit my form with the text input empty, the validator  
>>>>> does
>>>>> NOT
>>>>> get called. It only gets called if there is a value with the HTML  
>>>>> input
>>>>> field.
>>>>>
>>>>> I was expecting that the validator would be invoked upon submission  
>>>>> even
>>>>> if
>>>>> the text field is empty, in order to validate tha value "null". At  
>>>>> least
>>>>> this is what I understand as far as INullAcceptingValidator goes.
>>>>> However,
>>>>> this does not appear to happen. Instead, Wicket goes on to call the
>>>>> form's
>>>>> onSubmit() method with the value "null" inside my model.
>>>>>
>>>>> What am I missing?
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...