O'Reilly logo

PrimeFaces Cookbook - Second Edition by Oleg Varaksin, Mert Çalışkan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Selecting rows in dataTable

There are several ways to select a row or multiple rows, such as line selection and selection with radio buttons and 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="#{dataTableBean.cars}"
  selection="#{dataTableBean.selectedCar}"> <p:column> <p:commandButton value="Select" update=":mainForm:display" oncomplete="carDialog.show()"> <f:setPropertyActionListener value="#{car}" target="#{dataTableBean.selectedCar}" /> </p:commandButton> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required