empty TextField to null not empty string

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

empty TextField to null not empty string

Dan-2
Hello,

In Tapestry 3.0.x submission of empty text field will initialize property
binded to this field with empty string (sometimes called a blank string).
Is there any chance to set this property to null instead ?

e.g. I have an Contact bean with optional property let's say lastName.
I would like to have this property null if user left this field blank.

How can I achieve this (in whole app of course)?

Regards
Dan


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

Reply | Threaded
Open this post in threaded view
|

Re: empty TextField to null not empty string

pferraro
I think the easiest way to change this behavior globally is to implement
your own TextField component:

public abstract class TextField extends org.apache.tapestry.form.TextField
{
    public void updateValue(String value)
    {
        getValueBinding().setString(((value != null) && (value.length()
 > 0)) ? value : null);
    }
}

Paul

Dan wrote:

>Hello,
>
>In Tapestry 3.0.x submission of empty text field will initialize property
>binded to this field with empty string (sometimes called a blank string).
>Is there any chance to set this property to null instead ?
>
>e.g. I have an Contact bean with optional property let's say lastName.
>I would like to have this property null if user left this field blank.
>
>How can I achieve this (in whole app of course)?
>
>Regards
>Dan
>
>
>---------------------------------------------------------------------
>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
|

Re: empty TextField to null not empty string

Dan-2
Paul Ferraro <pmf8 <at> columbia.edu> writes:

>
> I think the easiest way to change this behavior globally is to implement
> your own TextField component:
>
> public abstract class TextField extends org.apache.tapestry.form.TextField
> {
>     public void updateValue(String value)
>     {
>         getValueBinding().setString(((value != null) && (value.length()
>  > 0)) ? value : null);
>     }
> }

Thanks a lot Paul !
Ineed this is the easiest way ;)
Personally I thought about some configuration magic and so on...

Regards
Dan




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