Book Image

Mastering JavaServer Faces 2.2

By : Anghel Leonard
Book Image

Mastering JavaServer Faces 2.2

By: Anghel Leonard

Overview of this book

Table of Contents (20 chapters)
Mastering JavaServer Faces 2.2
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The JSF Life Cycle
Index

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 adding a radio button per row will result in a column as shown in the following screenshot:

However, adding radio buttons in the <h:column> tag using the <h:selectOneRadio> tag doesn't...