ZK 6 (binding to css properties)
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:
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
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".
ZK - Open Source Ajax Java Framework
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?