I will be grateful, if you help me , so thank you in advance. I'm using PrimeFaces. I have a dynamic database table. I don't have problems with creating this table but I want to view this table using datatable and columns
Here is the part where I add database 's table content in an ArrayList
:
elts = new ArrayList<String>();
try {
Statement stmt = conn.createStatement();
ResultSet RS = stmt.executeQuery("SELECT * FROM temporaire");
ResultSetMetaData metadata = RS.getMetaData();
nombreColonnes = metadata.getColumnCount();
for (int j = 1; j <= nombreColonnes; j++) {
cols.add("colonne" + j);
}
while (RS.next()) {
for (int i = 1; i <= nombreColonnes; i++) {
elts.add(RS.getArray(i).toString());
}
}
and the xhtml code of datatable is :
<p:dataTable value="#{templateBean.elts}" var="elts" rowIndexVar="indro" rows="10"
paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
columnsPerPageTemplate="5,10,15">
<p:columns value="#{templateBean.cols}" var="cols" columnIndexVar="index">
<f:facet name="header">
<h:outputText value="#{cols}"/>
</f:facet>
<h:outputText value="#{elts}"/>
</p:columns>
</p:dataTable>
and the problem is that the datatable i am getting is repeating the same element in each row like this:
col1Content | col1Content |col1Content | col1Content
col2Content |col2Content |col2Content |col2Content
...
Can you please help me where is the problem and what's wrong with my code? Thank you