Primefaces in-cell-editing not update data in database


I use Primeface 4.0 , JSF 2 and jpa in a JEE project , i used the example shown in Primefaces showcase data table in cell editing. Here is the HTML code

<ui:composition xmlns=""

<ui:define name="content">

 <rich:panel  style="width : 800px; height : 551px; " > 
     <f:facet name="header" >

<h:outputText value="Tableau des articles" align="center" style="FONT-SIZE: small;"/>

    <h:form id="form">
  <p:growl id="messages" showDetail="true"/>  

    <p:contextMenu for="cars" widgetVar="cMenu">     
        <p:menuitem value="Edit Cell" icon="ui-icon-search" onclick="PF('carsTable').showCellEditor();return false;"/>    
        <p:menuitem value="Hide Menu" icon="ui-icon-close" onclick="PF('cMenu').hide()"/>    

   <p:dataTable id="cars" var="car" value="#{articlesbean.LMatpilotaccess1}" editable="true" editMode="cell" widgetVar="carsTable">  

        <f:facet name="header">  
            Matériel du pilotage et accessoires 

  <p:ajax event="cellEdit" listenner="#{articlesbean.onCellEdit()}" update=":form:messages" /> 
        <p:column headerText="Serie" style="width:25%">                

                   <f:facet name="output"><h:outputText value="#{car.serie}" /></f:facet>  
                   <f:facet name="input"><p:inputText id="modelInput" value="#{car.serie}" style="width:96%"/></f:facet>  

           <p:column headerText="Prix unitaire HTVA" style="width:25%">               

                   <f:facet name="output"><h:outputText value="#{car.puhtva}" /></f:facet>  
                   <f:facet name="input"><p:inputText id="modelInput5" value="#{car.puhtva}" style="width:96%"/></f:facet>  

            <p:column headerText="Montant HTVA" style="width:25%">               

                   <f:facet name="output"><h:outputText value="#{car.monthtva}" /></f:facet>  
                   <f:facet name="input"><p:inputText id="modelInput8" value="#{car.monthtva}" style="width:96%"/></f:facet>  

            <p:column headerText="Montant TTC" style="width:25%">               

                   <f:facet name="output"><h:outputText value="#{car.montttc}" /></f:facet>  
                   <f:facet name="input"><p:inputText id="modelInput9" value="#{car.montttc}" style="width:96%"/></f:facet>  






and this is the Bean

package com.pfe.controller;

import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;

import org.primefaces.component.datatable.DataTable;
import org.primefaces.event.CellEditEvent;

import com.pfe.model.Matpilotaccess1;
import com.pfe.model.Matpilotaccess2;
import com.pfe.model.Poteaux;
import com.pfe.model.Travgc1;
import com.pfe.model.Travgc2;
import com.pfe.model.Travresurbain;


public class ArticlesBean implements Serializable{

    private ArticlesDAO articleDAO;
    private Matpilotaccess1 matpilotaccess1;
    private Matpilotaccess2 matpilotaccess2;
    private Poteaux poteaux ;
    private Travgc1 travgc1;
    private Travgc2 travgc2;
    private Travresurbain travresurbain;

    private List LMatpilotaccess1 = new ArrayList();
    private List LMatpilotaccess2 = new ArrayList();
    private List LPoteaux = new ArrayList();
    private List LTravgc1 = new ArrayList();
    private List LTravgc2 = new ArrayList();
    private List LTravresurbain = new ArrayList();

    public void onCellEdit(CellEditEvent event) {  
        Object oldValue = event.getOldValue();  
        Object newValue = event.getNewValue();  
        if(newValue != null && !newValue.equals(oldValue)) {  

            DataTable s = (DataTable) event.getSource();
            Matpilotaccess1 d = (Matpilotaccess1) s.getRowData();

            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);  
            FacesContext.getCurrentInstance().addMessage(null, msg);  
    } ///// getters and setters 

the problem here is that even /////////////// are not displayed which means there is a problem in the HTML code that prevent the execution of onCellEdit function !!!

Best Solution

I think you have only one problem: your code not call your articlesbean.onCellEdit() method.

Here is my simple which works fine (but i not mixed richfaces components with primefaces):

<h:form id="testForm">
            <p:growl id="messages" showDetail="true"/>
            <p:outputPanel id="testContainer">
            <p:dataTable id="testTable" value="#{}" var="entry" editable="true" editMode="cell">

                    <p:ajax event="cellEdit" listener="#{tableBean.onCellEdit}" process="@this" update=":testForm:messages"/>

The message correctly appear after the user edit in table. Please try to replace richfaces panel to primefaces panel may be that is occured this problem.

If you have some update problem in p:ajax you can use RemoteCommand. But in this case you need redesign your method in articlesbean to:

public void onCellEdit() {
//do some thing

and xhtml:

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


  <p:ajax event="cellEdit" oncomplete="onCellEdit()" /> 

RemoteCommand provides a way to execute JSF backing bean methods directly from javascript.

Please try it!

Related Question