【发布时间】:2015-07-13 20:47:22
【问题描述】:
我整个早上都在努力解决这个问题,但无法让它发挥作用。基本上,我无法通过 PrimeFaces 从 cellEdit 事件中获取新的 dataTable 值。
这是我的 XHTML 页面:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:form id="httpPolicyForm">
<p:dataTable id="httpTable" var="row" value="#{httpPolicyBean.rows}" editable="true" editMode="cell">
<f:facet name="header">
HTTP Policy
</f:facet>
<p:ajax event="cellEdit" listener="#{httpPolicyBean.onCellEdit}" update=":httpPolicyForm:httpTable" />
<p:column headerText="Property">
<h:outputText value="#{row.name}" />
</p:column>
<p:column headerText="Value">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{row.value}" /></f:facet>
<f:facet name="input"><p:inputText value="#{row.value}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</h:form>
这是我的监听方法:
public void onCellEdit(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
printRowValues();
if(newValue != null && !newValue.equals(oldValue)) {
logger.debug("Old: " + oldValue + ", New:" + newValue);
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
方法被调用,但 newValue 的值始终是旧值。此外,该表永远不会使用新值进行更新。但是,如果我再次单击单元格以再次编辑值,它会拉出新值。我不确定我做错了什么。请帮我解决这个问题。
bean 是 SessionScoped。
【问题讨论】:
标签: jsf jsf-2 primefaces datatable