Reputation: 21105
I'm working with the multiple row selection to give a user ability to delete the selecting records. According to the PDF documentation, and the ShowCase Labs, I must use the code translated to the Java like that:
final DataTable = new DataTable();
...
// (1)
dataTable.setSelectionMode("multiple");
// (2)
dataTable.setValueExpression("selection", createValueExpression(DbeBean.class, "selection", Object[].class));
// (3)
dataTable.setValueExpression("rowKey", createValueExpression("#{" + VARIABLE + ".indexKey}", Object.class));
...
final ClientBehaviorHolder dataTableAsHolder = dataTable;
...
// (4)
dataTableAsHolder.addClientBehavior("rowSelect", createAjaxBehavior(createMethodExpression(metaData.controllerBeanType, "onRowSelect", void.class, new Class<?>[] {SelectEvent.class})));
public void setSelection(T[] selection)
is only invoked.getIndexKey()
is invoked and returns the necessary result.DbeBean.onRowSelect(SelectEvent e)
.I also use lazy data model (I don't really believe it may be the reason but who knows?; by the way, it returns List<T>
though setSelection() requires T[]
-- why it's like that?):
public abstract class AbstractLazyDataSource<T extends IIndexable<K>, K> extends LazyDataModel<T> {
...
@Override
public final List<T> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
...
final IResultContainer<T> resultContainer = getData(querySpecifier);
final List<T> data = resultContainer.getData();
setRowCount(resultContainer.getTotalEntitiesCount());
return getPage(data, first, pageSize);
}
...
@Override
public final K getRowKey(T object) {
return object.getIndexKey(); // T instanceof IIndexable<K>, have to return a unique ID
}
...
However, the handlers do not work as they are expected to work. Please help me to understand why (2) DbeBean.setSelection(T[] selection)
& (4) DbeBean.onRowSelect(SelectEvent e)
get only the null value: T[] selection = null
, and SelectEvent: e.getObject = null
, respectively. What am I doing wrong?
Thanks in advance.
Upvotes: 0
Views: 3160
Reputation: 21105
I've got it to work: I simply removed the rowKey
property during to the dynamic p:dataTable
creation (DataTable), and simply overloaded getRowData
in lazy data model. Now it works.
Upvotes: 1