Search code examples
jsfjsf-2icefacesicefaces-3

How get row index of <ace:dataTable> in every row?


In searching I found that we can do something with rowStateVar or rowIndex attributes of <ace:datatable>, but how?

I tried using <h:outputText value="#{myDataTableVar.rowIndex}"> but it shows an error message that myDataTableVar has no property rowIndex.


Solution

  • For a component library independent way, just use UIData#getRowIndex() as every component library specific datatable extends from this base component.

    In the below example, x: can be anything: standard JSF h:, ICEfaces ice: or ace:, PrimeFaces p:, RichFaces rich:, etc.

    <x:dataTable binding="#{table}" ...>
        <x:column>#{table.rowIndex}</x:column>
    </x:dataTable>
    

    Note: the binding="#{table}" is as-is! You don't need to bind it to some managed bean property.