Displaying row numbers
By default, JSF doesn't provide a method for displaying row numbers. But as you can see in the screenshot depicting the output in the Editing/updating a table row section, there is a column named No that displays row numbers. You can obtain this column in at least two ways. The simplest workaround consists of binding the table to the current view, as shown in the following code:
<h:dataTable value="..." binding="#{table}" var="t"> <h:column> <f:facet name="header">No</f:facet> #{table.rowIndex+1}. </h:column> ...
Another approach is to obtain it using the DataModel
class, which has the getRowIndex
method to return the currently selected row number. In order to do that, you need to wrap the collection in a DataModel
class.
The example named ch6_7
contains the first approach of this task.