2

In order to get the row numbers of a datatable I got an answer here that I could bind the dataTable directly to the view (JSF 2 dataTable row index without dataModel).

I'm using that function in a composite component and there may be several of those in the same page. I believe that the binding makes it impossible to use more than one component on each page; is it possible to bind each table "separately" somehow?

Community
  • 1
  • 1
nivis
  • 913
  • 3
  • 17
  • 34
  • Well you will bind each table on different managed bean, or on different properties of backing bean? Why would it be the problem? – partlov Feb 04 '13 at 14:29

2 Answers2

1

Create a backing component class with an UIData property.

@FacesComponent("fooComponent")
public class FooComponent extends UINamingContainer {

    private UIData table;

    // +getter +setter
}

And bind it to #{cc.table} instead (the #{cc} refers the current backing component instance).

<cc:interface componentType="fooComponent">
    ...
</cc:interface>
<cc:implementation>
    <h:dataTable binding="#{cc.table}" ...>
        <h:column>#{cc.table.rowIndex + 1}</h:column>
        ...
    </h:dataTable>
</cc:implementation>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

Just use ui:repeat instead, it has built in support via varStatus.index.

Neuralrank
  • 503
  • 4
  • 7