I have a problem to display a string as a header of an row and a list of strings, which are the propertys of the header. Unfortunately, the data table is not displayed. I want to use p:columns to later sort and filter my data. What is the right approach to display a nested list in a Primefaces DataTable?
My bean:
public class MyBean implements Serializable {
private List<TableData> tableData = new ArrayList<TableData>();
public void fillData(){
this.tableData.add(new TableData("Key1", valueList));
this.tableData.add(new TableData("Key2", valueList2));
this.tableData.add(new TableData("Key3", valueList3));
...
...
...
}
public List<TableData> getTableData() {
return tableData;
}
public void setTableData(List<TableData> tableData) {
this.tableData = tableData;
}
}
My model:
public class TableData {
private String key;
private List<String> values = new ArrayList<String>();
public TableData(String key, List<String> values) {
this.key = key;
this.values = values;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public List<String> getValues() {
return values;
}
public void setValues(List<String> values) {
this.values = values;
}
}
My .xhtml
<p:dataTable value="#{myBean.tableData}" var="data">
<p:columns value="#{data.values}" var="value">
<f:facet name="header">
<h:outputText value="#{data.key}" />
</f:facet>
<h:outputText value="#{value}" />
</p:columns>
</p:dataTable>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…