0

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="http://www.w3.org/1999/xhtml"
               xmlns:ui="http://java.sun.com/jsf/facelets"
               xmlns:f="http://java.sun.com/jsf/core"
               xmlns:h="http://java.sun.com/jsf/html"
               xmlns:rich="http://richfaces.org/rich"
               xmlns:a4j="http://richfaces.org/a4j"
               xmlns:p="http://primefaces.org/ui"
               xmlns:c="http://java.sun.com/jsp/jstl/core"
               template="/WEB-INF/templates/default.xhtml">


<ui:define name="content">
<center>






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

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


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

   <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 
        </f:facet>  


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

               <p:cellEditor>  
                   <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:cellEditor>  
           </p:column>  





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

               <p:cellEditor>  
                   <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:cellEditor>  
           </p:column>





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

               <p:cellEditor>  
                   <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:cellEditor>  
           </p:column>

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

               <p:cellEditor>  
                   <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>  
               </p:cellEditor>  
           </p:column>

    </p:dataTable>  


    </h:form>




</rich:panel>






</center>
</ui:define>



</ui:composition>

and this is the Bean

package com.pfe.controller;

import java.io.Serializable;
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.data.ArticlesDAO;
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;

@ManagedBean(name="articlesbean")

@ViewScoped
public class ArticlesBean implements Serializable{

    @Inject
    private ArticlesDAO articleDAO;
    @Inject
    private Matpilotaccess1 matpilotaccess1;
    @Inject
    private Matpilotaccess2 matpilotaccess2;
    @Inject
    private Poteaux poteaux ;
    @Inject
    private Travgc1 travgc1;
    @Inject
    private Travgc2 travgc2;
    @Inject
    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();  
          System.out.println("////////////////////////);
        if(newValue != null && !newValue.equals(oldValue)) {  

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

            articleDAO.Updatetable(d);
              System.out.println("///////////////////");
            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 !!!

Bellil Med Samouel
  • 321
  • 2
  • 8
  • 20
  • Why did you accept the answer if it didn't solve the problem at all? – BalusC Nov 19 '13 at 10:12
  • possible duplicate of [Updating entire on complete of ](http://stackoverflow.com/questions/19548838/updating-entire-pdatatable-on-complete-of-pajax-event-celledit) – BalusC Nov 19 '13 at 10:14
  • @BalusC because i wanted to reach 15 points , so i can upload a photo that would better explain problems that i face , as you see my english is not that fluent and i think that people don't answer my questions cause they don't get what i mean !! – Bellil Med Samouel Nov 20 '13 at 10:20
  • @BalusC i saw [Updating entire on complete of ](http://stackoverflow.com/questions/19548838/updating-entire-pdatatable-on-complete-of-pajax-event-celledit) but the answer didn't help me !! – Bellil Med Samouel Nov 20 '13 at 10:22

2 Answers2

1

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="#{tableBean.data}" 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!

herry
  • 1,708
  • 3
  • 17
  • 30
  • now i got another error!!! `javax.el.MethodNotFoundException: Method not found: com.pfe.controller.ArticlesBean@1bb3a11.onCellEdit()` – Bellil Med Samouel Nov 16 '13 at 09:16
  • i think that onCellEdit() function must take something!! – Bellil Med Samouel Nov 16 '13 at 09:18
  • and how can i bring the new object ?? – Bellil Med Samouel Nov 16 '13 at 09:33
  • Sorry for late response. What is status of this issue now? Are you solved the bring parameter problem? – herry Nov 16 '13 at 23:53
  • No , the same error persists !! have you any idea that can help me? – Bellil Med Samouel Nov 17 '13 at 09:46
  • So, you get the `javax.el.MethodNotFoundException: Method not found: com.pfe.controller.ArticlesBean@1bb3a11.onCellEdit()` - because this bean doesn't have onCellEdit() method. This bean has onCellEdit(CellEditEvent event). Second problem is the remoteCommand in atcionListener use ActionEvent not CellEditEvent. If you want use cellEdit features, please first try my code in edited answer. – herry Nov 17 '13 at 15:38
  • Well ...i'm sorry to tell you that the edited code is not working !! and it's not displaying any error !! – Bellil Med Samouel Nov 17 '13 at 16:20
  • i removed richfaces componenents and tried but it didn't solve the problem , thank you very much @herry but the problem is solved [here](http://stackoverflow.com/questions/20030887/primeface-data-table-in-cell-editing-i-cant-get-the-edited-object) – Bellil Med Samouel Nov 20 '13 at 11:25
  • @BellilMedSamouel If my answer not solved your problem or it doesn't help in any case, please don't accept it! Now I don't see any answer, may be there is deleted. So if you not posted you, this answer will be misleading. I think duplicate questions it doesn't supported in any case! – herry Nov 20 '13 at 12:52
1

I resolved similar problem but it took me nearly 3 days to notice that for JSF getters must be real getters (again). I mean that the list provided by the tableBean.getData() must be a real getter providing list initialized ideally in void method annotated with @PostConstruct. JSF will generated a Proxy class around the bean and all the code to reflect changes in the table. You have to write only the code implementing action reacting on the change (persist change in database, async action, whatever ...).

If the "list getter" is not a real getter and returns another list (in my example I filtered the list in the original field), all changes are lost before invoking the "listener method" - they are replaced by the original list.

dmatej
  • 1,518
  • 15
  • 24