对 dataTable 使用 PrimeFaces.current().ajax().update
使用 PrimeFaces 6.2,我目前正在尝试使用 ajax 来更新 ap:dataTable 的特定行,但遇到了麻烦。更新数据表的语句位于 bean 中 cellEdit 的事件处理程序中,因为我希望仅在执行 cellEdit 处理程序执行的编辑后才更新表。
这是我期望更新前端的部分:
public void onCellEdit(CellEditEvent edit) {
/// Do some modifications to a particular element in the backing data structure...
...
DataTable dataTable = (DataTable)
FacesContext.getCurrentInstance().getViewRoot().findComponent("addForm:myDT");
for(UIColumn col : dataTable.getColumns()) {
PrimeFaces.current().ajax().update(col.getClientId());
RequestContext.getCurrentInstance().update(col.getClientId());
for(UIComponent child : col.getChildren()) {
PrimeFaces.current().ajax().update(child.getClientId());
RequestContext.getCurrentInstance().update(child.getClientId());
}
}
}
请注意,我只是想在这里详尽无遗,我知道 RequestContext.update 已被弃用,尽管我不确定子级(即 outputText 和 inputText)是否应该是更新目标或父列。我天真地假设更新父列将更新子列,但这只是一个假设。
我确信支持数据结构(对象列表)肯定正在被修改。我可以通过断点调试观察到列表的元素与前端的元素不匹配。
虽然我没有在文档中看到它,但 .getClientId() 返回单元格的 id 以及在 CellEditEvent 中修改的行的行号。
任何关于为什么 PrimeFaces.current().ajax().update 或 RequestContext.getCurrentInstance().update 在此实例中不更新前端的建议将不胜感激。
Using PrimeFaces 6.2, I am currently trying to use ajax to update specific rows of a p:dataTable, but am having trouble. The statements which update the dataTable are in an event handler for cellEdit in a bean, as I'd like the table to be updated only after the edits performed by the cellEdit handler are performed.
Here is the section I am expecting to update the front end:
public void onCellEdit(CellEditEvent edit) {
/// Do some modifications to a particular element in the backing data structure...
...
DataTable dataTable = (DataTable)
FacesContext.getCurrentInstance().getViewRoot().findComponent("addForm:myDT");
for(UIColumn col : dataTable.getColumns()) {
PrimeFaces.current().ajax().update(col.getClientId());
RequestContext.getCurrentInstance().update(col.getClientId());
for(UIComponent child : col.getChildren()) {
PrimeFaces.current().ajax().update(child.getClientId());
RequestContext.getCurrentInstance().update(child.getClientId());
}
}
}
Note that I am just trying to be exhaustive here, I am aware RequestContext.update is deprecated, though I am unsure whether the children (i.e. outputText and inputText) is what should be targeted for update, or the parent column. Naively I assume updating the parent column will update the children, but this is just an assumption.
I am certain the backing data structure, a list of objects, is definitely being modified. I can observe the elements of the list do not match what is in the front end with breakpoint debugging.
Though I have not seen it in the documentation, .getClientId() is returning the id of the cell with the row number of the row which was modified in the CellEditEvent.
Any advice on why PrimeFaces.current().ajax().update or RequestContext.getCurrentInstance().update are not updating the front end in this instance would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论