0

a little dirty trick to solvebinding issue

asked 2007-05-29 08:59:03 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4334430

By: devilgary

I found an issue with data binding as I tried to use data binding with my application.
It's not really a bug but i think it will create headache for us. After struggling couple hours, I found a dirty trick to workaround this problem and would like to share it wit you guys.

Below is snippet of the code

<a:bind value="myBean.text1;save-when:self.onChange"/>
<textbox id="txt1" onChanging="txt2.value = event.value"/>

<a:bind value="myBean.text2;save-when:self.onChange"/>
<textbox id="txt2"/>

Class MyBean just simple get and set methods of txt1 and txt2.

How it works
The code's actually pretty straight forward. Whatever we write in txt1 will be copied to txt2 and save to corresponding attribute in class MyBean.

The issue
What's wrong with this code? Just type something in txt1 then move the cursor on something else. Now, you will see empty value on txt2!!!. It should be there but apparently data binding doesn't occur on txt2. Please note "save-when" can only have single definition of event from java doc.

How to solve
<a:bind value="myBean.text1;save-when:self.onChange"/>
<textbox id="txt1" onChanging="txt2.value = event.value"/>

<a:bind value="myBean.text2;save-when:txt1.onChange"/>
<textbox id="txt2" onChange="myBean.setTxt2(self.value)"/>

Explanation
"save-when:txt1.onChange" => The value of txt2 will be saved as the onChange method was called from txt1 hence this will prevent the empty value issue after lost focus on txt1.

But this is not enough.. This gonna create a new problem. For example, if we modify the value of txt2 the value won't be saved in MyBean.txt2. It will use the value of txt1 instead.

So we need another code to cope that problem =) onChange="myBean.setTxt2(self.value)" => Anything we write/modify in txt2 will be saved in the myBean. Hence all problems are solved now!!

I admit this dirty trick is kinda break the rule for data binding but I couldn't find a better way to workaround it.


Regards,

Gary Purnomosidi



delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2008-11-04 09:39:36 +0800

adigbolojackson gravatar image adigbolojackson
9

I'm actually lookin for a way i can bind pictures on my zul page to a model class(the set and get class)
and write to a database

link publish delete flag offensive edit

answered 2008-11-05 17:11:02 +0800

msrednsi gravatar image msrednsi
106 2

Another approach to solve binding dependency.

I have a very, i mean a really very complex data interface, if we compare with the above example. It impossible to manage dependencies one by one. What i do is to listen to event changes from every component and issue in a late event a binder.loadAll() (postEvent).

It's running very fine, i'm very happy with the solution; this is one the reasons i choose zk vs. other frameworks: data binding.

Congratulations to the zk team!!!

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: 2007-05-29 08:59:03 +0800

Seen: 282 times

Last updated: Nov 05 '08

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