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.
preRenderView
event listener on your xhtml? 3)When doesdoInit()
get called, is it a@PostConstruct
method? I've never tried a dataModel with multiple selection, so I want to replicate this scenario in order to give you an answer! – rion18