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

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.