嗯,好吧,如果有人有兴趣的话,我一步一步地在一系列简单问题上链接我对ZK框架和MVVM模式的疑虑:
Selected Item data from a table to textbox in ZK
现在,所有数据都正确绑定,我决定玩我的表单日期。所以我的想法就是当我选择一个日期时,它会计算一个操作的天数并将其显示在另一个文本框中,这里是代码:
.zul文件
<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)"/>
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);
}
其中&#34; hoy&#34; =今天的日期和getFechaRegistro =注册日期,它假设它必须计算另一个文本框中的天数,但它不起作用。可能是绑定问题或计算问题。我感谢任何解决我的问题的建议。非常感谢你。
答案 0 :(得分:1)
我想你的文本框绑定到diasEstancia
属性?然后
您应该让命令通知更改该值:
@NotifyChange({"diasEstancia"})
您没有使用属性fechaIngreso
(绑定到您的日期框)来计算日差,但您使用的this.getFechaRegistro()
不会更改从发布的代码看。因此,diasEstancia
中的值永远不会改变(在某一天)。