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. ...

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.