You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by SantiagoA <s....@gmx.de> on 2009/02/25 09:21:15 UTC

how to avoid value set to null if value of textfield gets deleted

I have a TextField with some input.
If a user deletes the input and submit the setter sets the value to "NULL".
How can i avoid this behavior and force an empty String "" to bet set?

Thanks for any help!
Santiago
-- 
View this message in context: http://www.nabble.com/how-to-avoid-value-set-to-null-if-value-of-textfield-gets-deleted-tp22198221p22198221.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: how to avoid value set to null if value of textfield gets deleted

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
You are welcome.

Ernesto

On Wed, Feb 25, 2009 at 2:44 PM, SantiagoA <s....@gmx.de> wrote:

>
> I used a PropertyModel. Now i use my own extended PropertyModel which
> overrides the setObject-Method quite similar to your proposal.
>
> Thanks for the Help.
>
>
> reiern70 wrote:
> >
> > What kind of model are you attaching to a the text field? Anyway, you
> > could
> > always do:
> >
> > public class EmptyStringModel extend WhatEverModelYouAreUsing<String> {
> >
> >      .....Constructors....
> >
> >      public void setObject(String value) {
> >          if(value != null) {
> >              super.setObject(value);
> >          } else {
> >              super.setObject("");
> >          }
> >      }
> > }
> >
> > and use EmptyStringModel  instead of the one you are using now?
> >
> > Best
> >
> > Ernesto
> >
> > On Wed, Feb 25, 2009 at 9:21 AM, SantiagoA <s....@gmx.de> wrote:
> >
> >>
> >> I have a TextField with some input.
> >> If a user deletes the input and submit the setter sets the value to
> >> "NULL".
> >> How can i avoid this behavior and force an empty String "" to bet set?
> >>
> >> Thanks for any help!
> >> Santiago
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/how-to-avoid-value-set-to-null-if-value-of-textfield-gets-deleted-tp22198221p22198221.html
> >> Sent from the Wicket - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/how-to-avoid-value-set-to-null-if-value-of-textfield-gets-deleted-tp22198221p22203068.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: how to avoid value set to null if value of textfield gets deleted

Posted by SantiagoA <s....@gmx.de>.
I used a PropertyModel. Now i use my own extended PropertyModel which
overrides the setObject-Method quite similar to your proposal.

Thanks for the Help.


reiern70 wrote:
> 
> What kind of model are you attaching to a the text field? Anyway, you
> could
> always do:
> 
> public class EmptyStringModel extend WhatEverModelYouAreUsing<String> {
> 
>      .....Constructors....
> 
>      public void setObject(String value) {
>          if(value != null) {
>              super.setObject(value);
>          } else {
>              super.setObject("");
>          }
>      }
> }
> 
> and use EmptyStringModel  instead of the one you are using now?
> 
> Best
> 
> Ernesto
> 
> On Wed, Feb 25, 2009 at 9:21 AM, SantiagoA <s....@gmx.de> wrote:
> 
>>
>> I have a TextField with some input.
>> If a user deletes the input and submit the setter sets the value to
>> "NULL".
>> How can i avoid this behavior and force an empty String "" to bet set?
>>
>> Thanks for any help!
>> Santiago
>> --
>> View this message in context:
>> http://www.nabble.com/how-to-avoid-value-set-to-null-if-value-of-textfield-gets-deleted-tp22198221p22198221.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-avoid-value-set-to-null-if-value-of-textfield-gets-deleted-tp22198221p22203068.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: how to avoid value set to null if value of textfield gets deleted

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
What kind of model are you attaching to a the text field? Anyway, you could
always do:

public class EmptyStringModel extend WhatEverModelYouAreUsing<String> {

     .....Constructors....

     public void setObject(String value) {
         if(value != null) {
             super.setObject(value);
         } else {
             super.setObject("");
         }
     }
}

and use EmptyStringModel  instead of the one you are using now?

Best

Ernesto

On Wed, Feb 25, 2009 at 9:21 AM, SantiagoA <s....@gmx.de> wrote:

>
> I have a TextField with some input.
> If a user deletes the input and submit the setter sets the value to "NULL".
> How can i avoid this behavior and force an empty String "" to bet set?
>
> Thanks for any help!
> Santiago
> --
> View this message in context:
> http://www.nabble.com/how-to-avoid-value-set-to-null-if-value-of-textfield-gets-deleted-tp22198221p22198221.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: how to avoid value set to null if value of textfield gets deleted

Posted by Sergio García <sg...@denodo.com>.
If you retrieve the string using getModelObjectAsString() you will never
receive a null, because that method converts nulls to ""

SantiagoA wrote:
> 
> A null value won´t work for me, because I have to Map these values via
> Castor to XML and as result null values were deleted in Castor.
> At this point I need an empty String to make sure the value is mapped in
> Castor.
> 
> Thanks for the proposal anyway, 
> the solution above (Ernestos proposal) works fine for me!
> 
> 
> 
> jensiator wrote:
>> 
>> My experience is that null values a nice to use. What if you have a
>> optional email field? When the user starts to write something the email
>> validation kicks in. I think a lot of wickets validators uses Null in
>> that case. And I have used that i JSP/Struts programming to. I think its
>> better to handle the null values when you later use the model to do
>> something. 
>> 
>> Jens Alenius
>> 
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-avoid-value-set-to-null-if-value-of-textfield-gets-deleted-tp22198221p22204778.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: how to avoid value set to null if value of textfield gets deleted

Posted by SantiagoA <s....@gmx.de>.
A null value won´t work for me, because I have to Map these values via Castor
to XML and as result null values were deleted in Castor.
At this point I need an empty String to make sure the value is mapped in
Castor.

Thanks for the proposal anyway, 
the solution above (Ernestos proposal) works fine for me!



jensiator wrote:
> 
> My experience is that null values a nice to use. What if you have a
> optional email field? When the user starts to write something the email
> validation kicks in. I think a lot of wickets validators uses Null in that
> case. And I have used that i JSP/Struts programming to. I think its better
> to handle the null values when you later use the model to do something. 
> 
> Jens Alenius
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-avoid-value-set-to-null-if-value-of-textfield-gets-deleted-tp22198221p22203182.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: how to avoid value set to null if value of textfield gets deleted

Posted by jensiator <je...@megasol.se>.
My experience is that null values a nice to use. What if you have a optional
email field? When the user starts to write something the email validation
kicks in. I think a lot of wickets validators uses Null in that case. And I
have used that i JSP/Struts programming to. I think its better to handle the
null values when you later use the model to do something. 

Jens Alenius



-- 
View this message in context: http://www.nabble.com/how-to-avoid-value-set-to-null-if-value-of-textfield-gets-deleted-tp22198221p22198642.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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