0

ZK 8 Form Object How to get Value

asked 2016-01-06 05:56:13 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

updated 2016-01-07 05:52:59 +0800

cor3000 gravatar image cor3000
6280 2 7

Hello

In ZK 7, we used to get the middle object field value as follows

ZUL Code

<textbox value="@bind(fx.ICDCode1)" maxlength="25"/>

VM Code

private Form myForm = new SimpleForm(); icdcode = (String) myForm.getField("ICDCode1");

What is the way to get the same in ZK 8 ?

delete flag offensive retag edit

Comments

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

8 Answers

Sort by ยป oldest newest most voted
1

answered 2016-01-06 07:15:57 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

There are lot of cases as follows

  1. Say for example, You have combo box and other text boxes, user select some value in the combo box and after that thru java code, we will fillip the values in the text box. Now user can leave the populated values or they can change. In this case, i can simply use

myForm.setField(propertName, value);

  1. Even before save button is hit, i want to do some logic based on the value entered in one input and press tab . In that case, i can use as follows

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 ?

link publish delete flag offensive edit

Comments

Totally agree here. I am not sure how all the use cases I implemented with SimpleForm and subclasses should be done with the new concept.

Matze2 ( 2016-04-01 13:37:00 +0800 )edit
0

answered 2016-01-06 07:18:30 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

There are lot of cases as follows

  1. Say for example, You have combo box and other text boxes, user select some value in the combo box and after that thru java code, we will fillip the values in the text box. Now user can leave the populated values or they can change. In this case, i can simply use

myForm.setField(propertName, value);

  1. Even before save button is hit, i want to do some logic based on the value entered in one input and press tab . In that case, i can use as follows

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 ?

link publish delete flag offensive edit
0

answered 2016-01-06 07:38:19 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2016-01-06 07:38:56 +0800

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

link publish delete flag offensive edit

Comments

How to get reference outside command

Senthilchettyin ( 2016-12-10 08:58:26 +0800 )edit

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
0

answered 2016-01-06 07:44:54 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

@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

link publish delete flag offensive edit

Comments

I don't see a relation to a toString method, I am using your Insurance object with a toString method and it works for me

cor3000 ( 2016-01-07 05:09:24 +0800 )edit
0

answered 2016-01-06 08:17:57 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

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");
}
link publish delete flag offensive edit
0

answered 2016-01-07 05:08:00 +0800

cor3000 gravatar image cor3000
6280 2 7

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");
}
link publish delete flag offensive edit

Comments

Sorry to jump so late on this topic. I also used SimpleForm (or self-implemented subclasses of it) to be able to monitor changes in the form fields and also to set form field values from outside. It is not clear where and how the above @command is called.

Matze2 ( 2016-04-01 13:34:09 +0800 )edit

commands are fired where ever you define them e.g. when clicking a button <button label="prefill" onClick="@command('prefillForm', form=fx)"/>

cor3000 ( 2016-04-07 02:43:53 +0800 )edit

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

this sounds like an uncommon usage but still this is possible by implementing a custom MethodHandler and intercepting arbitrary method calls

cor3000 ( 2016-04-07 07:39:54 +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 )edit
0

answered 2016-01-08 13:23:08 +0800

czekan gravatar image czekan
1
http://jakspelnicmarzenia...

loks very interesting for me

link publish delete flag offensive edit
0

answered 2016-01-13 13:02:15 +0800

vandoor gravatar image vandoor
9 1

updated 2016-01-13 13:04:18 +0800

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;
}
link publish delete flag offensive edit

Comments

Does not work for me

Senthilchettyin ( 2016-12-10 09:03:48 +0800 )edit

It is giving null

Senthilchettyin ( 2016-12-10 09:09:45 +0800 )edit
Your answer
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
3 followers

RSS

Stats

Asked: 2016-01-06 05:56:13 +0800

Seen: 101 times

Last updated: Jan 13 '16

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