1
votes

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: [email protected]()

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

2

2 Answers

2
votes

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

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