Java Reference
In-Depth Information
The value we would like each checkbox in the table to have is the index of the object
whose data is being displayed in its row. The
RowKey
class has a
getRowId()
method
that returns a numeric
String
object representing the index of the current row,
which happens to coincide with the index of the current object in the array. Therefore
all we need to do is obtain the
RowKey
for each row, and return the value of its
getRowId()
method:
public String getSelectedValue() {
RowKey rowKey = (RowKey) getValue("#{currentRow.tableRow}");
if (rowKey != null) {
return rowKey.getRowId();
} else {
return null;
}
}
Now we have created a read only property in our managed bean, we need to bind
it to the
selectedValue
attribute of our checkbox. This can be done by following a
very similar procedure to the one we used for its
selected
property. We need
to right-click on the checkbox, select
Property Bindings...
, then click on either the
Advanced
or
All checkbox
, then select the
selectedValue
bindable property and the
selected property of the
CustomerList
managed bean as the binding target.