Selecting rows in dataTable
There are several ways to select a row or multiple rows, such as line selection or selection with radio buttons or checkboxes, from the dataTable
component. We will cover all the possibilities in this recipe.
How to do it...
To make a single selection possible with a command component, such as commandLink
or commandButton
, f:setPropertyActionListener
can be used to set the selected row as a parameter to the server side.
<p:dataTable id="withCommand" var="car" value="#{dataTableController.cars}" rowKey="#{car.name}"selection="#{dataTableController.selectedCar}">
<p:column>
<p:commandButton value="Select" update=":mainForm:display" oncomplete="carDialog.show()">
<f:setPropertyActionListener value="#{car}"target="#{dataTableController.selectedCar}" />
</p:commandButton>
</p:column>
...
</p:dataTable>
The selection
attribute needs to be bound to a Car
reference in order to get the selected data.
There's more...
The selectionMode...