【问题标题】:Primefaces dynamic columns not renderedPrimefaces动态列未呈现
【发布时间】:2023-03-22 09:14:01
【问题描述】:

由于某种原因,我的表没有呈现动态列。我已经阅读了类似的帖子 (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>

期望输出:

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

但我看到的只是:

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

【问题讨论】:

标签: primefaces datatable dynamic-columns


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我以前遇到过这个问题。这可能会起作用:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-19
      • 2011-11-15
      • 2013-06-08
      • 2021-11-11
      • 1970-01-01
      • 2015-04-24
      • 1970-01-01
      相关资源
      最近更新 更多