-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello
In ZK 7, we used to get the middle object field value as follows
ZUL Code
VM Code
private Form myForm = new SimpleForm(); icdcode = (String) myForm.getField("ICDCode1");
What is the way to get the same in ZK 8 ?
There are lot of cases as follows
myForm.setField(propertName, value);
String icdVersion = (String) myForm.getField("icdVersion");
Robert.
I am losing my confident on going forward on ZK 8 with new Data binding approach. From your question, it looks like we cannot do this any more in ZK 8 ? am i right ?
There are lot of cases as follows
myForm.setField(propertName, value);
String icdVersion = (String) myForm.getField("icdVersion");
Robert.
I am losing my confident on going forward on ZK 8 with new Data binding approach. From your question, it looks like we cannot do this any more in ZK 8 ? am i right ?
You can easily do that, and that's one of the MAJOR advantages of the proxy based approach: No need to lose your confidence in ZK8.
e.g. you have a command binding (fx is a form proxy for your Pojo)
@command('cancel', form=fx)
in your command handler you do:
@Command("cancel")
public void cancel(@BindingParam('form') Pojo pojoForm) {
//pojoForm is a proxy around your original object keeping track of the changes
pojoForm.getIcdVersion();
// will give the value cached in the proxy, not yet committed to the original object
}
If you need to initalize and prepopulate some values in the Form you can manually create a proxy:
Pojo originalPojo;
Pojo pojoForm = ProxyHelper.createProxyIfAny(originalPojo); //form proxy around the pojo
pojoForm.setIcdVersion(123456); //will set the value in the form only, does not affect the original yet
I hope that clarifies the usage for you
Hi Senthil (long time no see) I assume your question got truncated a bit (or you forgot to add the details) Can you give some information what you mean by "reference" and "outside command". I assume you know that in Java object references are either stored at an object, or passed as method argument
cor3000 ( 2016-12-12 05:56:59 +0800 )edit@Command("cancel") public void cancel(@BindingParam('form') Pojo pojoForm) { //pojoForm is a proxy around your original object keeping track of the changes pojoForm.getIcdVersion(); // will give the value cached in the proxy, not yet committed to the original object }
The above works only if the Domain does not have toString method. Look at my previous ZK Forum post
Ok Thanks. Also can you please tell me how to make dirty from java side. In zk 7, WE USE the following way
postBeanValue("icdVersion", "10");
public void postBeanValue(String propertName, Object value) {
myForm.setField(propertName, value);
BindUtils.postNotifyChange(null, null, myForm, propertName);
BindUtils.postNotifyChange(null, null, ((FormExt) myForm).getStatus(),
"dirty");
}
assume this command binding giving you a form proxy reference
@command('prefillForm', form=fx)
and now in the handler you can cast the proxy object into the org.zkoss.bind.Form interface to retrieve the status and notify the dirty attribute
@Command
public void prefillForm(@BindingParam("form") Insurance form) {
form.setName("test");
BindUtils.postNotifyChange(null, null, form, "name");
BindUtils.postNotifyChange(null, null, ((Form)form).getFormStatus(), "dirty");
}
E.g. the Form.setValue method was overridden to react on changes of certain form fields. This means I need to add @command to "interesting" onChange events now? Maybe I'm missing something and I need to look deeper in the new concept. But currently it seems that not everything is possible anymore...
Matze2 ( 2016-04-07 06:31:42 +0800 )edit((Proxy) proxy).setHandler(new FormProxyHandler<Pojo>(pojo) { @Override public Object invoke(Object self, Method m, Method p, Object[] args) throws Exception { if(m.getName().startsWith("set")) { System.out.println(this.toAttrName(m)); } return super.invoke(self, m, p, args); } });
cor3000 ( 2016-04-07 07:42:51 +0800 )editloks very interesting for me
Hi!
Outside command context you can try this!
String formId = (String) selfComponent.getAttribute(BinderCtrl.FORM_ID);
Form form = (Form) selfComponent.getAttribute(formId);
selfComponent is set by
@AfterCompose
public void initSelfComponent(@ContextParam(ContextType.VIEW) Component view) {
this.selfComponent = view;
}
Asked: 2016-01-06 05:56:13 +0800
Seen: 101 times
Last updated: Jan 13 '16
when creating a new form it will be empty, what is the purpose to call getField even in ZK 7?
cor3000 ( 2016-01-06 06:50:51 +0800 )edit