JSF 保留旧数据



我有一个PrimeFaces按钮,它应该通过Java处理数据并将其显示在dataTable中。

这是代码:

<p:dataTable rowIndexVar="rowIndex" var="report" 
id="TableResult" 
style="height:685px;width: 97vw;" 
value="#{reportResultController.resultRows}" 
resizableColumns="true"
scrollable="true"
scrollHeight="95%"
scrollRows="30"
liveScroll="true"
lazy="false"/>

和按钮 呈现表的数据 ((:

<p:commandButton value="Report "
action="#{ReportController.produceReport}" id="produce_report"
update="TableResult"
process="TableResult"/>

这是Java部分

public void produceReport() {
resultRows = reportResultUtils.runReport(rph, rowsLimit); //Returning List of rows
}
public List<Object[]> getResultRows() {
return resultRows;
}

数据的过程工作正常。 问题是,在我为相同数据按下按钮两次的情况下,我第一次看到结果,下次我看到它翻倍而不是一次。

第一次

身份证名称

1 大卫

2 乔

第二次

身份证名称

1 大卫

2 乔

1 大卫

2 乔

第三次和第四次只保持第二次的两倍。

如果我更改参数以获得不同的表,以便它清除表而不是混淆数据。

在 resultRows var 中设置新数据之前,我该怎么做才能只显示一次或删除表中的数据?

好的

事实证明,这是一个PrimeFace的错误。

事实上,正如@Kukeltje提到的,问题出在liveScroll="true". 当我删除它时,它可以工作。

因此,解决方法是将Rows属性添加到与scrollRows大小相同的数据表中:

<p:dataTable rowIndexVar="rowIndex" var="report" 
id="TableResult" 
style="height:685px;width: 97vw;" 
value="#{reportResultController.resultRows}" 
resizableColumns="true"
scrollable="true"
scrollHeight="95%"
scrollRows="30"
rows="30"  <!-- This is the solution-->
liveScroll="true"
lazy="false"/>

最新更新