1

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.

3
  • why not just use p:dataGrid? primefaces.org/showcase/ui/data/dataGrid.xhtml Commented Sep 25, 2015 at 15:37
  • This is not possible with a datatable directly. But if you transpose your data yourself it is easy. But with 4 or 5 users it becomes a nightmare to read. So a p:datagrid is easier Commented Sep 25, 2015 at 15:43
  • Possible duplicate of Flipped over dataTable primefaces Commented Aug 16, 2016 at 19:55

1 Answer 1

1

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:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.