2
I’m unable to generate these columns dynamically with the p:repeat
of the Primefaces.
Is there no way to do this in Primefaces? Or is there no way to do it? There is a better solution?
The problem is this, I have an array with the headers I need to generate the columns and depending on how this array is, they will be generated n
counas.
<p:dataTable value="#{managedbean.dados}" var="dado">
<p:column headerText="Header 1">
<h:outputText value="#{dado.nome}"/>
</p:column>
<p:repeat value="#{managedbean.colunas}" var="coluna">
<p:column headerText="#{coluna}">
//por enquanto ainda não fiz a lógica para pegar a coluna correta que vou extrair de 'dado'
</p:column>
</p:repeat>
</p:dataTable>
Example situation:
If I have the array colunas
as follows:
colunas[0] = "coluna0"
colunas[1] = "coluna1"
colunas[2] = "coluna2"
I would want 3 columns to be generated in the table, from that array
DataTable
Header1 | coluna0 | coluna1 | coluna2
I’m not sure that would work. But you already have the data formed and want to display the columns in a conditional way? (Using the classic example of Individual and Legal Person, display one column with CPF and another with CNPJ, and the attributes already exist in the entity). If so, I think it would be better to use the rendered in p:column.
– Marcus Martins
@Marcusmartins will improve the post, not only that, but I will need the
rendered
.– Henrique Santiago