How to display the row index in a JSF datatable


In a JSF dataTable I want to display the row index next to the rows… like:

Column A    Column B
1           xxx
2           yyy

I thought that I could use an implicit el variable like #{rowIndex} but this is not working.

A solution I found is to create a binding for the data table and use the binding like:

<h:dataTable var="item" value="#{controller.items}" binding="#{controller.dataTable}">

but this solution is complex and doesn't work well when I have many nested dataTables in a page.

Any ideas on how to solve this in a better way?

Best Solution

This solution was posted by Jamie Williams on CodeRanch. He says it works with Tomahawk. I'm using primefaces, which also supports it.

<t:dataTable rowIndexVar="row" value="#{someBean.value}">  
        <h:outputText value="#{row + 1}"/>  
Related Question