Jasker
Jasker

Reputation: 53

Display a nested list with Primefaces dataTable

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>

Upvotes: 1

Views: 934

Answers (1)

Jasker
Jasker

Reputation: 53

This helped me alot to solve my Problem. My problem was, i used the wrong data structure.

Upvotes: 1

Related Questions