Selecting a single row

The easiest implementation of such a task is to provide a button for each row in the table. When a button is clicked, it can pass the selected row, as shown in the following code:

<h:dataTable value="#{playersBean.dataHashSet}" var="t" border="1">
  <h:column>
    <f:facet name="header">Select</f:facet>
    <h:commandButton value="#" action="#{playersBean.showSelectedPlayer(t)}"/> 
    </h:column>
...

Since the showSelectedPlayer method receives the selected row, it can process it further with no other requirements. The complete example is available in the code bundle of this chapter, and is named ch6_8_1.

Generally speaking, selecting one item from a bunch of items is a job for a group of radio buttons. In a JSF table, items are rows, and ...

Get Mastering JavaServer Faces 2.2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.