I cannot figure out why setter is called after onChange method in ZK Framework. In my zul file I have a datebox:
<datebox id="date" value="@bind(form.date)" width="100%" />
for which I am binding a value from a form, where I have proper getter and setter.
@Form("MyForm")
public class MyForm {
private Date date;
public MyForm {}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
In my Modal screen I am injecting a form and trying to get a value from form in onChange method, but the setter is called after onChange part.
@Screen
public class MyScreen {
@Autowired
@Qualifier("MyForm")
private MyFormform;
private Datebox date;
@Override
public MEALS_Form getForm() {
return form;
}
public void onChange$date(InputEvent event) {
System.out.println(form.getDate());
}
}
Can someone advice me here? Why setter is not called first in this case?
When debugging an MVVM binding, a good option is to enable the built-in MVVM debugger in zk.xml:
This will output a lot of logs, so make sure to only activate it in dev environment, not production.
Regarding specifics of how the BindComposer works: If the bind composer detects a change of value of the datebox, it will attempt to fulfil the save part of the @bind(form.date) expression (@bind == @save + @load). This is triggered by the host datebox triggering onChange. This said, you also have a different event listener also listening to datebox onChange, so there is no guarantee of which will be called first.
To do that, it should attempt to call form.setDate(...)
The extra wrinkle here is that I am not familiar with the annotations used in your project (@screen, @form) in a ZK context.
In addition, the onChange$date syntaxt looks more like GenericForwardComposer than MVVM binding? So I'm not really clear about the structure actually being used.
Is it possible to build a reproducing case in zkfiddle and send that link?