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

*爱你&永不变心* 提交于 2019-12-11 07:38:09

问题


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

When I remove the CellEditEvent argument, then it works. But I actually need the old and the new value. How can I proceed?


回答1:


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.

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.

  • EDITED -

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



回答2:


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



来源:https://stackoverflow.com/questions/20030887/primefaces-data-table-in-cell-editing-i-cant-get-the-edited-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!