Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
792 views
in Technique[技术] by (71.8m points)

java - 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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...