You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Alexandros Karypidis <ak...@yahoo.gr> on 2011/06/03 11:00:31 UTC

INullAcceptingValidator behavior

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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: INullAcceptingValidator behavior

Posted by Alexandros Karypidis <ak...@yahoo.gr>.
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  
<ak...@yahoo.gr> 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  
> <mg...@apache.org> 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  
>> <ak...@yahoo.gr> 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: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>

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


Re: INullAcceptingValidator behavior

Posted by Alexandros Karypidis <ak...@yahoo.gr>.
https://issues.apache.org/jira/browse/WICKET-3767

On Fri, 03 Jun 2011 12:56:06 +0300, Alexandros Karypidis  
<ak...@yahoo.gr> 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  
> <mg...@apache.org> wrote:
>
>> Yes. It looks like a bug
>>
>> On Fri, Jun 3, 2011 at 12:47 PM, Alexandros Karypidis  
>> <ak...@yahoo.gr> 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  
>>> <mg...@apache.org>
>>> 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  
>>>> <ak...@yahoo.gr>
>>>> 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: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>

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


Re: INullAcceptingValidator behavior

Posted by Alexandros Karypidis <ak...@yahoo.gr>.
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 <mg...@apache.org>  
wrote:

> Yes. It looks like a bug
>
> On Fri, Jun 3, 2011 at 12:47 PM, Alexandros Karypidis  
> <ak...@yahoo.gr> 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  
>> <mg...@apache.org>
>> 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  
>>> <ak...@yahoo.gr>
>>> 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: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>

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


Re: INullAcceptingValidator behavior

Posted by Martin Grigorov <mg...@apache.org>.
Yes. It looks like a bug

On Fri, Jun 3, 2011 at 12:47 PM, Alexandros Karypidis <ak...@yahoo.gr> 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 <mg...@apache.org>
> 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 <ak...@yahoo.gr>
>> 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: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



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

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


Re: INullAcceptingValidator behavior

Posted by Alexandros Karypidis <ak...@yahoo.gr>.
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 <mg...@apache.org>  
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  
> <ak...@yahoo.gr> 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>

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


Re: INullAcceptingValidator behavior

Posted by Martin Grigorov <mg...@apache.org>.
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 <ak...@yahoo.gr> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



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

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