【发布时间】:2015-12-13 23:57:26
【问题描述】:
当我在 ui:repeat 或 p:dataList 中使用 primefaces p:displayTable 时,结果显示有问题。错误的意思是,第一个表定义了下表的列,而不是预期的 DynamicDataTableCatalog-columns-count。
我的声誉不足以发布图片... (output png on an other website...) 所以我用简单的 html 编写输出:
<div>
<table id="firstTableWhichDefinesTheColum">
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
</table>
<table id="secondTableWithOnlyOneColumn">
<tr>
<td>d</td>
<td>random content or empty, because no data is available</td>
<td>random content or empty, because no data is available</td>
</tr>
</table>
</div>
这是错误的代码:
<p:dataList value="#{evaluateEntriesMBean.dataTables}"
var="qC" type="definition">
<p:panel header="Übersicht #{qC.catalog.name}"
styleClass="defaultPanelClass subGradient">
<p:dataTable value="#{qC.userAnswers}" var="userAnswer"
tableStyle="margin: auto; width: auto;">
<p:column headerText="Mitarbeiter"
style="text-align: right; width: auto">
<h:outputText value="#{userAnswer.user.geteMail()}" />
</p:column>
<p:columns value="#{qC.columns}" var="column"
columnIndexVar="index"
style="#{evaluateEntriesMBean.getStyleOfAnswer(userAnswer,index)}" >
<f:facet name="header">
<div title="#{column.tooltipText}">
<h:outputText value="#{column.name}" />
</div>
</f:facet>
<div title="#{evaluateEntriesMBean.getTextOfAnswer(userAnswer,index)}" >
<p:graphicImage url="/resources/img/green-trafficlight.png"
width="24"
rendered="#{evaluateEntriesMBean.getTrafficLightOfAnswer(userAnswer,index) == 'Green'}" />
<p:graphicImage url="/resources/img/yellow-trafficlight.png"
width="24"
rendered="#{evaluateEntriesMBean.getTrafficLightOfAnswer(userAnswer,index) == 'Yellow'}" />
<p:graphicImage url="/resources/img/red-trafficlight.png"
width="24"
rendered="#{evaluateEntriesMBean.getTrafficLightOfAnswer(userAnswer,index) == 'Red'}" />
<p:graphicImage url="/resources/img/grey-trafficlight.png"
width="24"
rendered="#{evaluateEntriesMBean.getTrafficLightOfAnswer(userAnswer,index) == 'Unknown'}" />
</div>
</p:columns>
</p:dataTable>
</p:panel>
</p:dataList>
视图中使用的数据模型:
public class DynamicDataTableCatalog {
private QuestionCatalogHistory catalog;
private List<ColumnHeader> columns;
private List<UserAnswers> userAnswers;
//...
}
public class UserAnswers {
private User user;
private List<Answer> answers;
//...
}
public class ColumnHeader {
String name;
String tooltipText;
//...
}
当我用 ui:repeat 替换 p:dataList 时,输出是相同的。只有 c:forEach 有效,但不支持 ajax 更新...
我的依赖项(所有使用的库,包括版本):
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
我希望有人能告诉我这是一个错误还是我所做的错误实现......提前谢谢你!
这是 Primefaces 中的一个错误,目前尚未修复...
【问题讨论】:
-
我在您发布的代码中看不到您对 c:forEach 的使用。请更新。也许它可以帮助识别问题
-
无需过多介绍,但您使用的是相当旧的 PF 版本。您是否在最小的工作示例中尝试过使用更新版本(最多 5.x)的示例?那么结果如何呢?
-
当我用
替换 p:dataList - 标签时,当然还有结束标签,它可以工作,但是没有 ajax。 -
我已经用最新的 primefaces 5.2 尝试了这段代码,但这并没有修复错误。如果它是框架中的错误,那么仅 primefaces 就不是问题......
-
尝试 5.3-SNAPSHOT 或最新的精英版本。并检查问题列表。事情有时会得到解决
标签: jsf primefaces datatable uirepeat