0

ZK 6 (binding to css properties)

asked 2012-02-06 18:00:24 +0800

shumy gravatar image shumy
244 1

Since you are about to release the new binding system on ZK 6, I ask. Is it possible to bind to css properties?
The "Small Talks/2012/February/MVVM in ZK6: Form Binding" address an interesting question in the final. The dirty status indicator is binding to a image source, but and if I want it to bind to the css color property of a textbox?
If not possible, is there any other way to use the dirty status to change text color?

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2012-02-10 05:40:54 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

Hi shumy,

Do you mean you want set different style of modified content?
For form binding, the 'dirty' denotes 'the form is dirty' which means some fields of this form are modified,
but it is about the form, not specific field.

You can achieve your goal by normal MVVM way,
please refer to the simple sample:

ZKFiddle-Link

TestForm.java
package j35jf0ka$v1;

import java.util.*;

import org.zkoss.lang.Objects;

public class TestForm {
private String _id;
private String _name;
private Map<String, Object> _init = new HashMap<String, Object>();
private Map<String, Object> _dirty = new HashMap<String, Object>();
public TestForm () {

}
public TestForm (String id, String name) {
setId(id);
setName(name);
reset(id, name);
}
public String getId () {
return _id;
}
public void setId (String id) {
_id = id;
updateDirty("id", _id);
}
public String getName () {
return _name;
}
public void setName (String name) {
_name = name;
updateDirty("name", _name);
}
public void reset () {
reset (getId(), getName());
}
public void reset (String id, String name) {
_init.put("id", id);
_init.put("name", name);
updateDirty("id", _id);
updateDirty("name", _name);
}
public Map getDirty() {
return _dirty;
}
public void updateDirty (String attr, Object value) {
if (!org.zkoss.lang.Objects.equals(_init.get(attr), value))
_dirty.put(attr, new Boolean(true));
else
_dirty.put(attr, new Boolean(false));
}
}


TestVM.java
package j35jf0ka$v1;


import java.util.*;

import org.zkoss.bind.ValidationContext;
import org.zkoss.bind.Validator;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zul.*;

public class TestVM {
private TestForm _form;
public TestForm getForm () {
if (_form == null)
_form = new TestForm ("id", "name");
return _form;
}
public void setForm (TestForm form) {
_form = form;
}
@Command @NotifyChange("form")
public void updateAll() {}
@Command @NotifyChange("form")
public void reset () {
getForm().reset();
}
}


index.zul
<zk>
<style>
.dirty {
color: #AA2222;
}
</style>
<window apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('j35jf0ka$v1.TestVM')">
<groupbox hflex="true" mold="3d">
<grid hflex="true" >
<columns>
<column width="120px"/>
<column/>
</columns>
<rows>
<row>
<textbox value="@bind(vm.form.id)" sclass="@load(vm.form.dirty.id?'dirty':'')"
onChange="@command('updateAll')" />
</row>
<row>
<textbox value="@bind(vm.form.name)" sclass="@load(vm.form.dirty.name?'dirty':'')"
onChange="@command('updateAll')" />
</row>
</rows>
</grid>
</groupbox>
<button onClick="@command('reset')" label="set current value as default" />
</window>
</zk>

Regards,
ben

link publish delete flag offensive edit

answered 2012-02-10 15:55:49 +0800

shumy gravatar image shumy
244 1

Yea, but is a lot of code to do a simple function.
It will be a nice adition to add dirty fields automaticaly in the "fxStatus".

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-02-06 18:00:24 +0800

Seen: 237 times

Last updated: Feb 10 '12

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