我使用 Primefaces 3.5.jar 和 Hibernate。我对数据表行编辑侦听器有问题。当我调试项目时,我可以输入 onCancel 方法,但 onEdit 永远不会启动。我的 XHTML 代码:
<f:facet name="header">
Workhours
</f:facet>
<p:ajax event="rowEdit" listener="#{workhoursBean.onEdit}" update=":form:messages" />
<p:ajax event="rowEditCancel" listener="#{workhoursBean.onCancel}" update=":form:messages" />
<p:column headerText="Start" style="width:20%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{workhours.workStart}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{workhours.workStart}" style="width:100%" label="Year"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="End" style="width:20%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{workhours.workEnd}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{workhours.workEnd}" style="width:100%" label="Year"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:6%">
<p:rowEditor />
</p:column>
</p:dataTable>
还有我的 Bean 方法:
public void onCancel(RowEditEvent event) {
//do stuff
}
public void onEdit(RowEditEvent event) {
Object oldValue = event.getObject();
Object newValue = event.getObject();
if(newValue != null && !newValue.equals(oldValue)) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
有谁知道为什么?