Primefaces datatable rowReorder获取行

时间:2015-09-29 20:37:02

标签: primefaces datatable

我尝试获取行对象,在我的类Story.class中,同时重新排序primefaces数据中的行。遗憾的是,我从ReorderEvent获取的索引是不够的,因为我有多个数据表,我想重用相同的rowReorder监听器。

这里有一些代码片段:

<p:ajax event="rowReorder"
                listener="#{reorderStoryView.onRowReorder}" />

以下代码行返回null:

Story story2 = context.getApplication().
      evaluateExpressionGet(context, "#{story}", Story.class);

以下代码行不返回当前rowData,有问题确定我得到的行数据:

Story story =(Story)((DataTable)event.getComponent()).getRowData();

无法找到有关此问题的任何其他信息,也许您可​​以帮助我。

提前谢谢

/ d

1 个答案:

答案 0 :(得分:0)

您可以阅读将此行添加到您的侦听器代码的源表:

String source = ((DataTable)event.getSource()).getClientId();

示例侦听器方法:

public void onRowReorder(ReorderEvent event) {
    int from = event.getFromIndex();
    int to = event.getToIndex();
    // the source table
    String source = ((DataTable)event.getSource()).getClientId();
    // Or String source =  event.getComponent().getClientId();
    // Access from backing bean (require reordering in backing bean)
    // reorderStoryView.stories.get(from)
    // reorderStoryView.stories.get(to)
    // Access to the moved row from table component
    DataTable myDatatable = (DataTable) FacesContext.getCurrentInstance()
        .getViewRoot().findComponent(source);
    Story story = myDatatable.getRowData(); 
    ...
}