PrimeFaces数据表单元内编辑:我无法获得编辑后的对象 [英] PrimeFaces data table In-Cell Editing : I can't get the edited object
问题描述
我正在尝试 DataTable-单元格编辑,如PrimeFaces中所示展示柜.由于以下问题,我已经修改了Facelets代码: primefaces单元内编辑不会更新数据库中的数据,因为<p:ajax event="cellEdit">
不会更新整个数据表.
I'm experimenting with DataTable - Cell Editing as shown in PrimeFaces showcase. I've modified the Facelets code as consequence of this question: primefaces in-cell-editing not update data in database because the <p:ajax event="cellEdit">
didn't update the entire data table.
<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>
远程命令操作方法定义如下:
The remote command action method is definied as follows:
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);
}
}
但是,永远不会调用此方法,并且会引发以下异常:
However, this method is never invoked and the following exception is thrown:
javax.el.MethodNotFoundException: Method not found: com.pfe.controller.ArticlesBean@1bb3a11.onCellEdit()
当我删除CellEditEvent
参数时,它就起作用了.但是我实际上需要旧的和新的价值.我该怎么办?
When I remove the CellEditEvent
argument, then it works. But I actually need the old and the new value. How can I proceed?
推荐答案
尝试一下
<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)
测试比较,但可以获得答案.
You won't be able to perform the !newValue.equals(oldValue)
test comparison but you will be able to obtain your answer.
public void onCellEditTableComplete(CellEditEvent event) {
DataTable dataTable = (DataTable) event.getSource();
OrderDetail oDetail = (OrderDetail) dataTable.getRowData();
oDetail.setQuantity(newQuantity);
...
}
将p:remoteCommand
忘在p:dataTable
之外,您就没有想要的" CellEditEvent
.
Forget the p:remoteCommand
as outside the p:dataTable
you have not the 'desired' CellEditEvent
.
- 已编辑-
如果对于同一张表,您必须显示一些基于此单元格的计算,则应从p:remoteCommand调用它.只需添加oncomplete="onCellEditTableComplete()"
并从表外进行更新
If for the same table, you have to show some calculations based in this cell, you should call it from a p:remoteCommand. Just add oncomplete="onCellEditTableComplete()"
and do the update from outside the table
<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()"/>
这篇关于PrimeFaces数据表单元内编辑:我无法获得编辑后的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!