0

A data Binding question.

asked 2012-07-10 03:27:19 +0800

ntsetso gravatar image ntsetso
59 1 4

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

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2012-07-10 04:35:54 +0800

rdgrimes gravatar image rdgrimes
735 7

updated 2012-07-10 04:41:02 +0800

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.

link publish delete flag offensive edit

answered 2012-07-10 04:40:49 +0800

MontyPan gravatar image MontyPan
435 3
http://xitop.blogspot.com...

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

link publish delete flag offensive edit

answered 2012-07-10 07:11:30 +0800

ntsetso gravatar image ntsetso
59 1 4

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

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-07-10 03:27:19 +0800

Seen: 179 times

Last updated: Jul 10 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More