gpt4 book ai didi

datagrid - 删除项目后 Primefaces dataGrid 内容不会更新

转载 作者:行者123 更新时间:2023-12-03 03:28:54 27 4
gpt4 key购买 nike

我有一个数据网格组件:

<h:form id="myForm">
<h:panelGroup id="statementDataContent" layout="block">

[... some controlls ...]

<p:dataGrid id="dg" columns="#{statementDataRequestAction.columnCount}" var="statement"
value="#{statementDataRequestAction.data}" rowIndexVar="#{statement.id}" >
<p:column>
<p:panelGrid columns="1" >

[... some controlls ...]
<p:commandButton value="-" immediate="true" type="submit" actionListener="#{statementDataRequestAction.remove(statement)}" process="@form" update="??? " />

</p:panelGrid>
</p:column>
</p:dataGrid>

如您所见,有一个按钮可以删除当前项目。它正确调用 bean,并且该方法从支持网格的列表中删除该项目。数据网格甚至刷新(我可以看到显示的列数减少了一),但网格元素内的值没有刷新。

代码里我特意写了???因为我尝试了几十种选择,包括:

  • 刷新网格:dg:myForm:dg
  • 刷新整个表单:@form:myForm:myForm:statementDataContent
  • 刷新其中的字段,但很难解决它们
  • 甚至一些奇特的东西,例如使用 p:remoteCommandp:collector*

我的 bean 在 SessionScope 中(无法更改它)。

为了帮助理解我的问题:想象一下这个起始状态:

Before delete

我的数据网格中有三个项目。现在我按下最左边(第一个)项目的删除按钮。日志表明正确的元素已从支持集合中删除:

Remove statement: 4 - StatementDataWrapper [id=4, data=Entity: 16 - hu.avhga.entities.StatementData, year=1000]
===============Removed: true :
[StatementDataWrapper [id=5, data=Entity: 17 - hu.avhga.entities.StatementData, year=1010], StatementDataWrapper [id=6, data=Entity: 18 - hu.avhga.entities.StatementData, year=1020]]

另外,下面的屏幕截图显示了之后的结果:

enter image description here

正如您所看到的,网格现在检测到只有两个项目要显示,但显示的两个是前两个。

请给我一些提示,因为我已经用完了。 :-(

提前致谢!

青草

最佳答案

PrimeFaces 提供的 p:commandButton 默认使用 AJAX,因此您应该设置 process="@none" 而不是设置 immediate 标志(Example in PrimeFaces showcase)。

还在 p:dataTable 中使用 p:commandButton 无法正常工作,但在 3.4 版中修复了(如果我没记错的话)。这也适用于 p:dataGrid

关于datagrid - 删除项目后 Primefaces dataGrid 内容不会更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13712300/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com