【发布时间】:2015-01-15 15:36:42
【问题描述】:
我有一个简单的问题,但我找不到正确的答案。
我渲染了一个非常复杂的数据表:
<p:dataTable var="label" value="#{labelsManager.labelsList}" rowKey="#{label.cod}" editable="true"
rowsPerPageTemplate="5,10,15,30" paginator="true" paginatorPosition="bottom" rows="30"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rendered="#{not empty labelsManager.labelsList}" scrollable="true" scrollHeight="300" id="labelsList" sortMode="multiple"
selection="#{labelsManager.selectedLabelsForDelete}">
<p:ajax event="rowEdit" listener="#{labelsManager.onRowEdit}" />
...some code...
</dataTable>
还有一个方法
public void onRowEdit(RowEditEvent event) {
... here I want to get the index on the current row...
}
当我想编辑一行时,我还想获取将要编辑的当前行的索引。我搜索了很多,但看不到如何从 RowEditEvent 中提取 id。
我也尝试将行的索引作为属性发送,但没有成功。有任何想法吗?谢谢!
【问题讨论】:
-
我想从将要更新的行中获取一个单元格的 ID,该行是动态创建的。例如 (tableForm:labelsList:1:myId) 其中 1 是 rowIndex
-
你可以使用
<f:setPropertyActionListener>在你的bean中设置rowIndex值,你试过吗? -
是的,我已经尝试使用 rowEditor
但我收到类似“ Parent is not of type ActionSource, type is: org.primefaces.component.roweditor .RowEditor@38523852 " -
你把
放进去了吗? -
是的,但是没有调用属性的设置器,我不知道为什么。我已经剪断了代码:
ajax> 其中 currentRow 是我的 bean 的属性
标签: jsf primefaces datatable