Primefaces动态列未呈现

时间:2015-02-22 13:51:13

标签: primefaces datatable dynamic-columns

由于某种原因,我的表没有呈现动态列。我已经阅读了类似的帖子(Primefaces static and dynamic columns in datatable),这正是我想要做的。我想我理解得很好。但它对我不起作用。也许,我错过了一些东西。

这是我的数据对象:

    public class DataSeries implements Serializable {
      private String resultType; // Either READ, WRITE or MIX
      private Map<String,String> points; 
      private List<String> columns;  // is fixed {"col1","col2","col3","col4"...}

      public DataSeries(String resultType, List<String> columns, Map<String,String> points) {
          this.resultType = resultType;
          this.points = points;
          this.columns = columns;
      }
      ... Getter and Setter for the aboves
  }

Backing Bean TestResultView

        resultData = new ArrayList<DataSeries>();
        ...
        ... Loop to populate 
        ....   List<String> uniqueLabels = ... (it represent columns and it's fixed length)
            Map<String,String> tuples = new HashMap();
            for (DataPoint point : points) {
                tuples.put(point.name, point.value);
            }

            DataSeries series = new DataSeries(type,uniqueLabels,tuples);              
            resultData.add(series);

这是我的xhtml

                    <p:dataTable id="datalist" value="#{TestResultView.resultData}" var="item" widgetVar="resultsTable">
                        <p:column headerText="Type">
                            <h:outputText value="#{item.resultType}" />
                        </p:column>
                        <p:columns value="#{item.columns}" var="column" headerText="#{column}" >
                            <h:outputText value="#{item.points.get(column)}" />
                        </p:columns>                            
                    </p:dataTable>

期待ouput:

    type |  col 1   | col 2    | ... 
    ----------------------------------------------------------------------
    READ |  xxx1    |  yyy1    | ... 
    WRITE|  xxx2    |  yyy2    | ... 
    MIX  |  xxx3    |  yyy3    | ... 

但我所看到的只是:

    type
    ----------------------------------------------------------------------
    READ
    WRITE
    MIX

2 个答案:

答案 0 :(得分:0)

你犯的错误与你所指的帖子完全相同。看那里的第一个答案

答案 1 :(得分:0)

之前我遇到过这个问题。这可能会奏效:

 <p:columns value="#{item.columns.toArray()}" var="column" headerText="#{column}">
    <h:outputText value="#{item.points.get(column)}" />
</p:columns>