I'm trying to build a <p:dataTable>
with row count but for some reason it shows only the first index in every row. Here is my code:
index.xhtml
<p:dataTable value="#{personBean.personListAsModel}" var="person">
<p:column headerText="No">
<h:outputText value="#{personBean.personListAsModel.rowIndex + 1}"/>
</p:column>
<p:column headerText="Last name">
<h:outputText value="#{person.lastName}"/>
</p:column>
<p:column headerText="First name">
<h:outputText value="#{person.firstName}"/>
</p:column>
</p:dataTable
PersonBean.java
@ManagedBean
@ViewScoped //The scope doesn't matter (I think)
public class PersonBean () {
private List<Person> personList;
public PersonBean() {
personList = new ArrayList<>();
// populate the list with Person objects (it's just a POJO with first and last name)
}
// get/set for personList
public ListDataModel<Person> getPersonListAsModel() {
return new ListDataModel(personList);
}
}
But when I display the table the result is something like this:
| No | Last Name | First Name |
|----|-----------|------------|
| 1 | Smith | John |
| 1 | Perez | Juan |
| 1 | Stallman | Richard |
| 1 | Gosling | James |
| 1 | Cagatay | Civici |
| 1 | Doe | Jane |
Is there something am I missing? Any guide/help is appreciated. Thanks in advance