Reputation: 2221
In my JSF page, I have a datatable like so:
<p:datatable var="item" value="#{bean.dataModel}" rowkey="#{item.pkey}" selectionMode="multiple" selection="#{bean.selectedItems}">
In my managedbean, I have declared selectedItems as a list like so
private List<SelectedItemsClass> selectedItems;
public void doInit() {
selectedItems = new ArrayList<SelectedItemsClass>();
}
I have also declared the getter and setter for selectedItems
. Now, when I try to debug one of my actions that checks for the selectedItems
, the value of selectedItems
size is always 0. Am I missing something in my code? I've tried to search the web and the answer is always to use selection="" in datatable. Please advise!
UPDATE: The cause of the problem had nothing to do with the data table and the datamodel itself. As it turns out, the problem was the data type I used for my rowkey in my datamodel class. I've set string value for the rowkey but my database is returns the key as type long. By changing the data type of my rowkey, the selectedItems are now passed successfully to my managedbean and I am able to process the selected Items from there. thank you very much for your time.
Upvotes: 0
Views: 805
Reputation: 1020
You need add ajax events in jsf datatable configuration, like this:
<p:dataTable ...>
<p:ajax event="rowSelectCheckbox" process="@this"/>
<p:ajax event="rowUnselectCheckbox" process="@this"/>
<p:ajax event="toggleSelect" process="@this" />
Upvotes: 2