简体   繁体   English

PrimeFaces数据表单元内编辑:我无法获得编辑后的对象

[英]PrimeFaces data table In-Cell Editing : I can't get the edited object

I'm experimenting with DataTable - Cell Editing as shown in PrimeFaces showcase. 我正在试验DataTable-单元格编辑 ,如PrimeFaces展示柜所示。 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. 由于以下问题,我修改了Facelets代码: 单元内编辑中的primefaces不会更新数据库中的数据,因为<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>

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()

When I remove the CellEditEvent argument, then it works. 当我删除CellEditEvent参数时,它将起作用。 But I actually need the old and the new value. 但是我实际上需要旧的和新的价值。 How can I proceed? 我该如何进行?

Try this 尝试这个

 <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> 

And

public void onValueQuantityChange(ValueChangeEvent event) {
    newQuantity = (Integer) event.getNewValue();
}

You won't be able to perform the !newValue.equals(oldValue) test comparison but you will be able to obtain your answer. 您将无法执行!newValue.equals(oldValue)测试比较,但可以获取答案。

public void onCellEditTableComplete(CellEditEvent event) {
    DataTable dataTable = (DataTable) event.getSource();
    OrderDetail oDetail = (OrderDetail) dataTable.getRowData();
    oDetail.setQuantity(newQuantity);
    ...
}

Forget the p:remoteCommand as outside the p:dataTable you have not the 'desired' CellEditEvent . 忘记在p:remoteCommand p:dataTable之外的p:remoteCommand ,您还没有“所需的” CellEditEvent

  • EDITED - 编辑-

If for the same table, you have to show some calculations based in this cell, you should call it from ap:remoteCommand. 如果对于同一张表,必须显示基于此单元格的一些计算,则应从ap:remoteCommand调用它。 Just add oncomplete="onCellEditTableComplete()" and do the update from outside the table 只需添加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()"/>

Try to do this: 尝试这样做:

<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>

[]'s []的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM