-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I'm working with a MySQL database.
Taking the following code:
First Name: <textbox value="@save(vm.person.firstname)"/>
If if textbox is empty, i.e., if First Name is not supplied, I end up with a zero length string in the corresponding field in the database.
What I want to achieve is: if textbox is empty the corresponding DB field should be null.
How can I do that?
TIA,
ntsetso
Presumably, your view model has a person object you are referencing, and in turn that person object has a firstname property, which should have a corresponding getter and setter. Your setter can check for the presence of a null argument and change it to an empty string.
From the sound of it, you are probably making your view model properties public, rather than making them private and having the BindComposer use the getter and setter methods instead, which it will do naturally without you needing to configure it to do so. See here , which does precisely what I'm talking about in using getters/setters instead of public properties. Notice how it uses 'selectedItem' and 'cartItems' as though it is referencing directly the private properties of the view model, but in fact it is tied to the getter/setter methods corresponding to said property.
Hi,
In my personal opinion, the requirement you want is not in ZK domain.
If you want do it in ZK's way, maybe converter will work (not sure).
reference: http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/MVVM/Data_Binding/Converter
Regards.
Monty Pan
Thank you for prompt help.
@MontyPan
You are right, I was looking in the wrong direction; that was not in zk domain.
@rdgrimes
I got the point.
That's how my code looks now:
private String firstname; public void setFirstname(String firstname){ this.firstname = (firstname == "" ? null : firstname); }
Regards.
ntsetso
Asked: 2012-07-10 03:27:19 +0800
Seen: 179 times
Last updated: Jul 10 '12