I have a h:dataTable that displays ProfileNotification like below:
<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>
when I dont have the item.createTime, if I click a commandLink to set renderProfileNotification=true, it print out 4 items. However, if i uncommented item.createTime, the it only print out 1 item, the first item.
EDIT: The problem is the [] inside value. Since BalusC suspect that this is an EL bug, I reproduce my bug in a small, readable and reproducible code. This code run on 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;
}
}
OK, it’s the last
]which is causing problems. When usingthe XML response of the ajax request is as follows:
Note the unnecessary CDATA blocks.
And when using
the XML response of the ajax request is as follows:
This boils down to the following problem cause: the ajax response handler is unnecessary closing and starting a CDATA block for a
]in partial response and the JS XML response parser only picks the first one for display. An easy workaround was to place the]outside the value expression:which results in the following XML response:
I am not sure yet where the problem is rooted, in the ajax response handler or in the JS XML response parser, but now we at least know the cause. I will report an issue to the Mojarra guys sooner or later once nailed down.
Update: OK, I nailed it further down: it’s the PrimeFaces’ ajax response handler and JS XML parser which doing this incorrectly. When using a Mojarra’s
h:commandLinkinstead ofp:commandLinkit works fine.Mojarra’s ajax response handler doesn’t print unnecessary CDATA blocks after each
]. That might be the root cause in PrimeFaces.Update: issue reported to PF guys: http://code.google.com/p/primefaces/issues/detail?id=1282