如何防止 PrimeFaces 可编辑数据表在变量中设置更新值?

How to prevent PrimeFaces editable DataTable from setting the updated value in a variable?

我的 PrimeFaces (7.0) DataTable 中有这些 ajax 听众:

<p:ajax event="rowEditInit" listener="#{editKey.onRowEditInit(event, key)}"/>
<p:ajax event="rowEdit" listener="#{editKey.onRowEdit(event, key)}"/>

我在 bean 中使用 onRowEditInit 将行的初始值保存在 oldKey 中,当它处于编辑模式时,效果很好。

private KeyManagementKeys oldKey;

public void onRowEditInit(RowEditEvent event, KeyManagementKeys key) {
    oldKey = key;
}

public void onRowEdit(RowEditEvent event, KeyManagementKeys newkey) {
    keylistService.updateKey(newkey, oldKey);
}

问题是,当我编辑 UI 中的行时,oldKey 会更新为编辑后的值。 所以当调用 onRowEdit 完成编辑时,newKeyoldKey 具有相同的值。

如何防止与 DataTable 值 (KeyManagementKeys) 具有相同类型的任何变量的这种自动值更新? 非常感谢任何帮助!

你能试试这个(我不知道 KeyManagementKeys 怎么样 class,所以代码可能需要一些更改),以解耦两个变量

public void onRowEditInit(RowEditEvent event, KeyManagementKeys key) {
    KeyManagementKeys oldKey = new KeyManagementKeys();
    BeanUtils.copyProperties(oldKey, key);
}