首页 > 解决方案 > 当 c:foreach 中有多个 p:datatable 时,事件 rowselect 与选定对象为 null

问题描述

我有一个 p:datatables 列表,每个我需要行选择事件。但只有最后一个数据表有效。如果我在其他数据表中选择一行,我会看到调用了 onRowSelected 方法,但对象为空。

我认为在 c:foreach 中,ajax 侦听器被覆盖,所以只有最后一个有效。怎么解决 ?

这是我的 xhtml 代码:

 <c:forEach items="#{azPrimaDisponibilita.selectedCompany}" var="companyCode" varStatus="loop">
   <p:dataTable id="tablePerformance_#{companyCode}" rendered="#{azFirstAvail.isCompanyVisible}"  widgetVar="tablePerformance" var="performance" value="#{azFirstAvail.listPerformances.get(loop.index)}" 
                styleClass="perfDataTable no-border" rowIndexVar="rowIndex"
                selectionMode="single" selection="#{azFirstAvail.selectedRowCompany}" rowKey="#{performance.id}">
      <p:ajax event="rowSelect" global="true" listener="#{azFirstAvail.onRowSelectCompany}" update="formPerformance,pageSubDescription,pageDescription"/>
    ....

标签: jsfprimefaces

解决方案


我解决了。widgetVar 在循环中是相等的,我需要在 widgetVar 中设置不同的 id


推荐阅读