Java 考虑集合属性的窗体的脏状态

Java 考虑集合属性的窗体的脏状态,java,zk,Java,Zk,我有以下型号: 人 public class Person { private String name; private Set<Phone> phones; // setters and getters } “我的视图”将创建如下表单: <groupbox form="@id('fx') @load(vm.selected) @save(vm.selected, before='save')"> 并将在文本框中显示姓名,在列表框中显示手机

我有以下型号:

public class Person {
    private String name;
    private Set<Phone> phones;
    // setters and getters
}
“我的视图”将创建如下表单:

<groupbox form="@id('fx') @load(vm.selected) @save(vm.selected, before='save')">

并将在文本框中显示姓名,在列表框中显示手机。每次选择手机时,我都会设置selectedPhone属性。可以使用“我的视图”上的其他文本字段编辑手机

当我更改名称时,我的表单的脏状态被更新,这很好。当我选择手机时,我可以看到设置了viewmodel的selectedPhone属性。但是,当我使用绑定到selectedPhone的editBox更改手机时,表单的脏状态没有改变

这是预期的,因为我正在更改ViewModel而不是表单。但是解决这个问题的方法是什么呢?因为当一部手机换了,意味着这个人也换了,因为有东西要保存

视图实现如下所示:

...
<groupbox form="@id('fx') @load(vm.selected) @save(vm.selected, before='save')" vflex="1">
    <textbox width="50px" value="@bind(fx.name)" />
    <listbox vflex="true" model="@load(fx.phones)" selectedItem="@bind(vm.selectedPhone)">
        <!-- shows the phone record -->
    </listbox>
    <textbox width="50px" value="@bind(vm.selectedPhone.number)" />
</groupbox>
....
。。。
....

当我更改名称时,它会更新表单(fx),其状态为脏。但是更改selectedPhone.number不会通过表单,因此不会标记为脏。phone是一个集合,如果fx集合中包含的phone属性发生了更改,如何在GUI中显示并将整个表单标记为脏的呢?

在考虑了一些情况后,对于我来说,有一个简单的解决方案,
只需添加一个附加对象,因为您的问题是无法访问
fx

因此,我们只需制作一个容器,这样您就有了一个新的
fx
,当您更改集合中的某些内容时,可以访问该容器

public class MyPersonContainer {
  private Person selected;
  private Phone selectedPhone;
  //getter/setter
}
并更改您的虚拟机

public class PersonViewModel {
   //private Person selected;
   //private Phone selectedPhone;
   private MyPersonContainer container;
   ...
}
以及你的看法

<groupbox form="@id('fx') @load(vm.container) @save(vm.container, before='save')">
<listbox vflex="true" model="@load(fx.selected.phones)" selectedItem="@bind(fx.selectedPhone)">
...
<textbox width="50px" value="@bind(fx.selectedPhone.number)" />

...

我添加了额外的评论,问题不在于通知,而在于如何在表单中处理集合。事实上,这并不是那么简单,如果你仔细研究这个问题,你会发现我是手机上的数字属性,它位于一个集合中,由vm使用的个人的属性引用,它应该或多或少像:@bind(vm.selected.phones[?].number),我不能手动处理这个问题,如果我手动处理,那么使用另一种方法比使用VMMV更容易。就我所知,在这种情况下没有这样的约束,对吧?谢谢纳比尔!经过多次尝试后,我实现了这样的功能。。。这不是我所期望的,但比当前的解决方案要好;)请为我定义“肮脏”,因为我不明白你的问题是什么。请查看的文档。但dirty state指的是已经从初始状态更改的内容,例如加载的bean,其属性已被用户更改(但未提交)。我编辑了我的awnser,希望能有所帮助。
<groupbox form="@id('fx') @load(vm.container) @save(vm.container, before='save')">
<listbox vflex="true" model="@load(fx.selected.phones)" selectedItem="@bind(fx.selectedPhone)">
...
<textbox width="50px" value="@bind(fx.selectedPhone.number)" />