Generate columns with repeat Primefaces

2

I'm not able to dynamically generate these columns with p:repeat of Primefaces.

Is there no way to do this in Primefaces? Or is there no way to do this? Is there 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, n counas will be generated.

<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>

Situation example:

If I have the array colunas as follows:

colunas[0] = "coluna0" 
colunas[1] = "coluna1" 
colunas[2] = "coluna2"

I would like 3 columns to be generated in the table, from this array

          DataTable
Header1 | coluna0 | coluna1 | coluna2
    
asked by anonymous 28.08.2017 / 22:44

1 answer

1

Only use <p:columns> , passing the array by the variable value and using the variable var

<p:columns value="#{managedbean.colunas}" var="coluna" headerText="#{coluna}">
    <h:outputText value="valor desejado"/>
</p:columns>
    
28.08.2017 / 23:29