Well, well, step by step i'm chaining all my doubts about ZK framework and MVVM pattern on a simple series of questions, if someone is interested:
Selected Item data from a table to textbox in ZK
Now, with all the data correctly binded, i decided to play around with the date of my form. So the idea is when i choose a date, it calculates the days with a operation and show it in another textbox, here is the code:
.zul File
<datebox id="" format="medium" onCreate="" value="@bind(vm.fechaIngreso)" width="100%"
onSelect="@command('calcularDias')" mold="rounded" readonly="true" constraint="no empty, no future"
disabled="@load(empty vm.camaPaciente)"/>
Command on Viewmodel
@Command
@NotifyChange({"fechaIngreso"})
public void calcularDias(){
long milisegundosPorDia = 24 * 60 * 60 * 1000;
java.util.Date hoy = new Date();
long tmp = (hoy.getTime() - this.getFechaRegistro().getTime())/milisegundosPorDia;
this.setDiasEstancia((int)tmp);
}
where "hoy" = today date and getFechaRegistro = registration date, it suppose it has to calculate the number of days in another textbox, but it doesn't work. Maybe is a binding problem or a calculation problem. i appreciate any suggestion of solution to my problem. Thank you very much.
I suppose your textbox is bound to the diasEstancia
property? then
you should let the command notify a change of that value:
@NotifyChange({"diasEstancia"})
You don't use the property fechaIngreso
(which is bound to your datebox) to calculate the day difference, but you use this.getFechaRegistro()
which is not changed as far as I see from the code posted. Therefore, the value in diasEstancia
never changes (at one day).