You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Thierry Leveque <tl...@gmail.com> on 2010/01/27 16:48:36 UTC

setRequired( false ) does not work on Integer textfield?

Here's what I have in my code:

TextField<Integer> lAdaptingHitCountThreshold = new TextField<Integer>(
"AdaptingHitCountThreshold", new PropertyModel<Integer>( lMcsConfig,
"Adapting.HitCountThreshold" ) );

lForm.add( lAdaptingHitCountThreshold.setRequired( false ) );

But when I execute it, if I do not enter any value in the field, I keep
getting the message "Field 'AdaptingHitCountThreshold' is required."
Why? In my pojo data object (lMcsConfig), the field is really of type "int",
but it is not required.

Is there a simple way to make this work? Other than creating my own model?

Thierry

Re: setRequired( false ) does not work on Integer textfield?

Posted by Thierry Leveque <tl...@gmail.com>.
Oups...
"always create "int" even if we specify "xs:integer" in the xsd..."

Of course!!!


Thierry


On Wed, Jan 27, 2010 at 10:55, Thierry Leveque <tl...@gmail.com> wrote:

> Yes... Thanks, that what I tought....
>
> The problem is that my Pojo object is in fact created by Castor (from an
> xsd), and Castor always create "Integer" even if we specify "xs:int" in the
> xsd...
> Castor add a method call has[name of the field] to replace the null value.
>
> I guess I will have to write my own implementation of PropertyModel that
> will handle that.
>
> Thierry
>
>
>
> On Wed, Jan 27, 2010 at 10:50, Johan Compagner <jc...@gmail.com>wrote:
>
>> an int (primitive) is always required.
>> We have to set it to something. cant be null
>> if you want to be able to not require it (so null) make it an Integer not
>> int
>>
>>
>> On Wed, Jan 27, 2010 at 16:48, Thierry Leveque <tl...@gmail.com>
>> wrote:
>>
>> > Here's what I have in my code:
>> >
>> > TextField<Integer> lAdaptingHitCountThreshold = new TextField<Integer>(
>> > "AdaptingHitCountThreshold", new PropertyModel<Integer>( lMcsConfig,
>> > "Adapting.HitCountThreshold" ) );
>> >
>> > lForm.add( lAdaptingHitCountThreshold.setRequired( false ) );
>> >
>> > But when I execute it, if I do not enter any value in the field, I keep
>> > getting the message "Field 'AdaptingHitCountThreshold' is required."
>> > Why? In my pojo data object (lMcsConfig), the field is really of type
>> > "int",
>> > but it is not required.
>> >
>> > Is there a simple way to make this work? Other than creating my own
>> model?
>> >
>> > Thierry
>> >
>>
>
>

Re: setRequired( false ) does not work on Integer textfield?

Posted by Thierry Leveque <tl...@gmail.com>.
Yes... Thanks, that what I tought....

The problem is that my Pojo object is in fact created by Castor (from an
xsd), and Castor always create "Integer" even if we specify "xs:int" in the
xsd...
Castor add a method call has[name of the field] to replace the null value.

I guess I will have to write my own implementation of PropertyModel that
will handle that.

Thierry


On Wed, Jan 27, 2010 at 10:50, Johan Compagner <jc...@gmail.com> wrote:

> an int (primitive) is always required.
> We have to set it to something. cant be null
> if you want to be able to not require it (so null) make it an Integer not
> int
>
>
> On Wed, Jan 27, 2010 at 16:48, Thierry Leveque <tl...@gmail.com> wrote:
>
> > Here's what I have in my code:
> >
> > TextField<Integer> lAdaptingHitCountThreshold = new TextField<Integer>(
> > "AdaptingHitCountThreshold", new PropertyModel<Integer>( lMcsConfig,
> > "Adapting.HitCountThreshold" ) );
> >
> > lForm.add( lAdaptingHitCountThreshold.setRequired( false ) );
> >
> > But when I execute it, if I do not enter any value in the field, I keep
> > getting the message "Field 'AdaptingHitCountThreshold' is required."
> > Why? In my pojo data object (lMcsConfig), the field is really of type
> > "int",
> > but it is not required.
> >
> > Is there a simple way to make this work? Other than creating my own
> model?
> >
> > Thierry
> >
>

Re: setRequired( false ) does not work on Integer textfield?

Posted by Johan Compagner <jc...@gmail.com>.
an int (primitive) is always required.
We have to set it to something. cant be null
if you want to be able to not require it (so null) make it an Integer not
int


On Wed, Jan 27, 2010 at 16:48, Thierry Leveque <tl...@gmail.com> wrote:

> Here's what I have in my code:
>
> TextField<Integer> lAdaptingHitCountThreshold = new TextField<Integer>(
> "AdaptingHitCountThreshold", new PropertyModel<Integer>( lMcsConfig,
> "Adapting.HitCountThreshold" ) );
>
> lForm.add( lAdaptingHitCountThreshold.setRequired( false ) );
>
> But when I execute it, if I do not enter any value in the field, I keep
> getting the message "Field 'AdaptingHitCountThreshold' is required."
> Why? In my pojo data object (lMcsConfig), the field is really of type
> "int",
> but it is not required.
>
> Is there a simple way to make this work? Other than creating my own model?
>
> Thierry
>