datatable - Rendering data from a query result in data table in primefaces -
i have database table contains answers given set of questions set of people(reviewer's) means there m*n(no. of questions * no. of people) records fetching using normal select query. have list of entity(entity class of database table) objects want show result on xhtml page in following format: 1. first column shows distinct questions. 2. rest of column header names of people answered it. 3. rest data should answer given particular reviewer against particular question.
how achieve in primefaces? appreciated. in advance :)
primefaces <p:datatable> can handle dynamic columns using <p:columns>. check documentation @ primefaces under datatable -> dynamic columns.
you need 2 things:
- create
list<string> columns, content{"question", "peter", "thomas", "andrew", ...}, - create
list<string[]> answersstring[]array have same size number of respondents + 1 , contain @ index 0 text of question followed user answers:{"what pin number?", "1234", "1122","2211",...}. careful maintain answer , user order.
your table in jsf page:
<p:datatable var="answer" value="#{foobean.answers}"> <p:columns var="columnname" value="#{foobean.columns}" columnindexvar="columnnumber"> <f:facet name="header"> <h:outputtext value="#{columnname}" /> </f:facet> <h:outputtext value="#{answer[columnnumber]}" /> </p:columns> </p:datatable>
Comments
Post a Comment