I use <h:dataTable> to list data from database. We have many records in page, now I would like to select multiple records with a checkbox in each row. How can I achieve this?
I use <h:dataTable> to list data from database. We have many records in page,
Share
I assume that your entity is that well-designed that it has an unique technical identifier, for example the auto increment sequence from the DB.
If not, you’ll need to add it.
Then, add a
Map<Long, Boolean>property to the bean which is tied to the table.(preinitialization can also happen in (post)constructor, take your pick, at least JSF won’t do it for you; oh, give it a getter as well, a setter is not necessary)
Then, add a column with a checkbox which maps to the boolean value by entity ID as key.
Now, in the action method associated with the delete button, you can collect and delete the checked items as follows: