我有一个h:dataTable
显示ProfileNotification
如下:
<h:dataTable value="#{myBean.profileNotifications}" var="item"
rendered="#{myBean.renderProfileNotification}">
<h:column>
<h:form>
<h:outputText value="#{item.userName} "/>
<h:outputText value="commented on your profile. "/>
<!-- <h:outputText value="[#{item.createTime}]"/> -->
</h:form>
</h:column>
</h:dataTable>
当我没有时item.createTime
,如果我单击 acommandLink
进行设置renderProfileNotification=true
,它会打印出 4 个项目。但是,如果我取消注释item.createTime
,它只会打印出一项,即第一项。
编辑:问题出在[]
里面value
。由于 BalusC 怀疑这是一个 EL 错误,所以我用一个小的、可读且可重现的代码来重现我的错误。此代码在 Glassfish v3.0.1 b22 上运行
index.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>TODO supply a title</title>
</h:head>
<h:body>
<h:form id="table">
<h:dataTable value="#{myBean.temp}" var="item" rendered="#{myBean.display}">
<h:column>
<h:outputText value="[#{item}]"/>
</h:column>
</h:dataTable>
</h:form>
<h:form>
<p:commandLink value="Display" actionListener="#{myBean.setDisplay}" update="table"/>
</h:form>
</h:body>
</html>
myBean.java
@ManagedBean(name="myBean")
@SessionScoped
public class myBean {
List<String> temp = null;
public myBean() {
}
private boolean display = false;
@PostConstruct
public void init(){
temp = new ArrayList<String>();
temp.add(0, "Tom");
temp.add(1, "Peter");
temp.add(2, "Mike");
temp.add(3, "Fox");
}
public List<String> getTemp() {
return temp;
}
public void setTemp(List<String> temp) {
this.temp = temp;
}
public boolean isDisplay() {
return display;
}
public void setDisplay() {
this.display = !this.display;
}
}