I am looking for a way to display a collection of data by column (instead of by row) in a jsf primefaces datatable component. For example, i have a bean named User and i want to display a list of User in a primefaces datatable : each User displayed in a separate column, each property (name, surname, ...) in a separate row. Do you know if it is possible with a datatable ? Thanks for your answers.
1 Answer
I think Primefaces dataTable can't afford your requirements. If you want to present your data in a landscape format you can use two nested <ui:repeat> loops. I'll show a basic example. You can refine it depending on your requirements:
<h:outputText value="Landscape Tabular Data Representation" /> <table> <tbody> <ui:repeat value="#{yourBean.fields}" var="field" > <tr> <th style="padding:.4em; background-color:#AFEEEE; border: .3em solid #FFFFFF;"> <h:outputText value="#{field}" /> </th> <ui:repeat value="#{yourBean.items}" var="item"> <td style="padding:.4em; background-color:#E0FFFF; border: .3em solid #FFFFFF;"> <h:outputText value="#{item[field]}" /> </td> </ui:repeat> </tr> </ui:repeat> </tbody> </table> Note: yourBean.fields is a collection with item attributes names. You can populate it manually or use Apache Commons BeanUtils or similar to obtain the names. You could also create your own landscape table composite component if you want.
This is the example output:

p:datagridis easier