我正在尝试DataTable - Cell Editing,如PrimeFaces展示中所示。我已经修改了Facelets代码作为这个问题的结果:primefaces in-cell-editing not update data in database因为<p:ajax event="cellEdit">
没有更新整个数据表。
<h:form id="form">
<p:outputPanel id="testContainer" deferred="true">
<p:growl id="messages" showDetail="true" />
<p:remoteCommand name="onCellEdit" action="#{articlesbean.onCellEdit()}" update=":form:messages" />
<p:dataTable id="cars" var="car" value="#{articlesbean.LMatpilotaccess1}" editable="true" editMode="cell" widgetVar="carsTable" update=":cars">
<p:ajax event="cellEdit" oncomplete="onCellEdit()" />
...
</p:dataTable>
</p:outputPanel>
</h:form>
远程命令操作方法定义如下:
public void onCellEdit(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
if(newValue != null && !newValue.equals(oldValue)) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
但是,永远不会调用此方法,并抛出以下异常:
javax.el.MethodNotFoundException: Method not found: com.pfe.controller.ArticlesBean@1bb3a11.onCellEdit()
当我删除CellEditEvent
参数时,它就可以了。但我实际上需要旧的和新的价值。我该怎么办?
答案 0 :(得分:1)
试试这个
<p:ajax event="cellEdit" listener="#{orderDetailController.onCellEditTableComplete}" update=":formGeneral:tabViewGeneral:growl :formGeneral:tabViewGeneral:OrderHeaderTableComplete"/>
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{orderDetail.quantity}" /></f:facet>
<f:facet name="input">
<p:inputText id="modelInput" value="#{orderDetail.quantity}" valueChangeListener="#{orderDetailController.onValueQuantityChange}"/></f:facet>
</p:cellEditor>
并且
public void onValueQuantityChange(ValueChangeEvent event) {
newQuantity = (Integer) event.getNewValue();
}
您将无法执行!newValue.equals(oldValue)
测试比较,但您将能够获得答案。
public void onCellEditTableComplete(CellEditEvent event) {
DataTable dataTable = (DataTable) event.getSource();
OrderDetail oDetail = (OrderDetail) dataTable.getRowData();
oDetail.setQuantity(newQuantity);
...
}
忘记p:remoteCommand
在p:dataTable
之外,而不是'所需'CellEditEvent
。
如果对于同一个表,您必须在此单元格中显示一些计算,则应从p:remoteCommand中调用它。只需添加oncomplete="onCellEditTableComplete()"
并从表格外部执行更新
<p:remoteCommand name="onCellEditTableComplete" update=":formGeneral:tabViewGeneral:OrderHeaderTableComplete " />
<p:dataTable ...>
<p:ajax event="cellEdit" listener="#{orderDetailController.onCellEditTableComplete}"
update=":formGeneral:tabViewGeneral:growl :formGeneral:tabViewGeneral:OrderHeaderTableResume"
oncomplete="onCellEditTableComplete()"/>
答案 1 :(得分:0)
尝试这样做:
<h:form id="form">
<p:outputPanel id="testContainer" deferred="true">
<p:growl id="messages" showDetail="true" />
<p:remoteCommand name="onCellEdit" action="#{articlesbean.onCellEdit()}" update=":form:messages" />
<p:dataTable id="cars" var="car" value="#{articlesbean.LMatpilotaccess1}" editable="true" editMode="cell" widgetVar="carsTable" update=":cars">
<p:ajax event="cellEdit" oncomplete="onCellEdit()" />
...
</p:dataTable>
</h:form>
</p:outputPanel>
[]&#39; S