Wednesday 23 October 2013

DataTable Row Selection Radio Checkbox Primefaces 4.0


DATATABLE ROW SELECTION RADIO CHECKBOX
Implementing a table that allows row selection either having a column of radio buttons or checkboxes
After good hours of struggle and deep search, I found out that, to use the feature as shown in this url, You must have Primefaces-4.0 or above. I was using primefaces 3.5 I couldn't get it working.

Helpful Threads I visited:
I visited many threads, but finally the 2 below helped me to come to a conclusion that the feature was still a major problem in the lower versions(3.5 and below).

Things that must be done to have this datatable working.
-Make sure your Bean implements selectableDataModel or include the rowKey property in the datatable definition.
-selection - (Getters and setters in the Bean. If selection mode is multiple, set and get and array. If the selection mode is single, set and get the object)
-selectionMode - (multiple/single)
-Include this line as one of your columns <p:column selectionMode="single/multiple but not both" style="width: 4%"/>. This is selection mode for radio or checkbox
-Don't include selectionMode in the Datatable definition (<p:datatable selectionMode=""/>) since this is selection mode for row selection. Reason: Row selection and radio/checkbox selection are not compatible and cannot be both enabled.

Do it like here http://www.primefaces.org/showcase/ui/datatableRowSelectionRadioCheckbox.jsf but make sure to add rowkey in <p:datatable ../>


Only me can access the code. Its in my Dropbox and it's protected.

4 comments:

  1. Hi there,
    Many many thanks for sharing your experience. It is really very very informative. I was stuck and clueless as my radio button was not displaying and was just about to give up, when I got this resource. Then I replace my primeface-jar-V-3.x with primeface-jar-V-4.x and it worked!!!! Thanks a lot.

    ReplyDelete
    Replies
    1. Thanks alot for your kind comment. This even motivates me to share more. Thanks again.

      Delete