You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by "florin.g" <fl...@bytenotes.com> on 2009/05/25 18:24:23 UTC

"" versus NULL in form values

When we do form.getFieldValue("afield") the return is an empty string "".
This appears to be convenient at times, yet is it not more appropriate to
have NULL returned when the value of the field is never set?


-- 
View this message in context: http://n2.nabble.com/%22%22-versus-NULL-in-form-values-tp2970512p2970512.html
Sent from the click-user mailing list archive at Nabble.com.


Re: "" versus NULL in form values

Posted by "florin.g" <fl...@bytenotes.com>.
Yes, it does. Thank you.

I'm using Ebean against PostgreSql for persistence and it complains of
foreign key violation when an empty string is used. If a form.copyTo(bean)
is used, the issue does not appear.

Enjoy the holiday. (?)


sabob wrote:
> 
> Hi Florin,
> 
> florin.g wrote:
>> When we do form.getFieldValue("afield") the return is an empty string "".
>> This appears to be convenient at times, yet is it not more appropriate to
>> have NULL returned when the value of the field is never set?
> 
> 
> Yes sometimes one is preferred above the other. getFieldValue 
> delegates to form.getValue() which returns the empty string even if 
> the value is null. This is convenient when rendering the value of a 
> Field, otherwise one will have to check for null throughout the code.
> 
> What you can do is use getValueObject which returns the Object 
> representation of the field value and won't interfere if the value is 
> truly null.
> 
> So you could instead do:
> 
>    form.getField("afield").getValueObject();
> 
> Hope this helps.
> 
> kind regards
> 
> bob
> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/%22%22-versus-NULL-in-form-values-tp2970512p2971157.html
Sent from the click-user mailing list archive at Nabble.com.


Re: "" versus NULL in form values

Posted by Bob Schellink <sa...@gmail.com>.
Hi Florin,

florin.g wrote:
> When we do form.getFieldValue("afield") the return is an empty string "".
> This appears to be convenient at times, yet is it not more appropriate to
> have NULL returned when the value of the field is never set?


Yes sometimes one is preferred above the other. getFieldValue 
delegates to form.getValue() which returns the empty string even if 
the value is null. This is convenient when rendering the value of a 
Field, otherwise one will have to check for null throughout the code.

What you can do is use getValueObject which returns the Object 
representation of the field value and won't interfere if the value is 
truly null.

So you could instead do:

   form.getField("afield").getValueObject();

Hope this helps.

kind regards

bob