Search code examples
javaprimefacesfacelets

Set p datatable header


I have the following datatable:

<p:dataTable value="#{openReportBean.rows}" var="row">                                      
    <p:columns value="#{openReportBean.columns}" var="col">
        <f:facet name="header">
            #{row[col].columnName}
        </f:facet>
        <h:outputText value="#{row[col]}"/>
    </p:columns>
</p:dataTable>

The problem is the column headers are set in the row variable, I can access them using row.columnName but they are not displayed. Can I do anything about that?


Solution

  • I think that correct definition of your header should be:

    <f:facet name="header">
            #{col.columnName}
    </f:facet>
    

    or reconsider having method in your backing bean that returns column name and then just call it in <f:facet name="header">