ajax - 如何防止 PrimeFaces 可编辑 DataTable 在变量中设置更新值?
问题描述
我的 PrimeFaces (7.0) DataTable 中有这些 ajax 侦听器:
<p:ajax event="rowEditInit" listener="#{editKey.onRowEditInit(event, key)}"/>
<p:ajax event="rowEdit" listener="#{editKey.onRowEdit(event, key)}"/>
我onRowEditInit
在我的 bean 中使用它来保存行的初始值,oldKey
当它处于编辑模式时,它工作正常。
private KeyManagementKeys oldKey;
public void onRowEditInit(RowEditEvent event, KeyManagementKeys key) {
oldKey = key;
}
public void onRowEdit(RowEditEvent event, KeyManagementKeys newkey) {
keylistService.updateKey(newkey, oldKey);
}
问题是,oldKey
当我在 UI 中编辑行时,它会更新为编辑后的值。所以通过onRowEdit
调用时间来完成编辑,newKey
并且oldKey
具有相同的值。
如何防止与 DataTable 值 ( KeyManagementKeys
) 具有相同类型的任何变量的自动值更新?任何帮助是极大的赞赏!
解决方案
你能试试这个(我不知道 KeyManagementKeys 类如何,所以代码可能需要一些更改),以解耦这两个变量
public void onRowEditInit(RowEditEvent event, KeyManagementKeys key) {
KeyManagementKeys oldKey = new KeyManagementKeys();
BeanUtils.copyProperties(oldKey, key);
}
推荐阅读
- java - ICU4J - 相同的货币符号作为前缀或后缀,取决于语言环境
- python - Visualizing a heatmap matrix on to an image in OpenCV
- xml - Multiple conditions in domain odoo 8
- matrix - 如何使用 rand() 和特定比例创建二进制矩阵?
- macos - ORSSerialPort 不发送数据
- imagemagick - ImageMagick - change the background color of the selected bounding box
- tensorflow-serving - Tensorflow Serving: InvalidArgumentError: Expected image (JPEG, PNG, or GIF), got unknown format starting with 'AAAAAAAAAAAAAAAA'
- php - 你能在 USE 之后停止 PHP 命名空间引用吗?
- java - Java中是否有用于创建工具箱的预设或者是否有用于它的程序?
- r - 在 R 中求解具有非线性约束的非线性凸优化问题