0

I've followed PrimeFaces showcases to use row editing datatable but i can't see why it's not updating data.

here's my datatable:

<p:dataTable id="tab" var="art" value="#{myMB.allArticles}" editable="true" style="margin-bottom:20px">
   <f:facet name="header">

   </f:facet>

   <p:ajax event="rowEdit" listener="#{myMB.onRowEdit}" update=":form:msgs" />
   <p:ajax event="rowEditCancel" listener="#{myMB.onRowCancel}" update=":form:msgs" />

   <p:column headerText="Name ">
       <p:cellEditor>
           <f:facet name="output"><h:outputText value="#{art.name}" /></f:facet>
           <f:facet name="input"><p:inputText id="modelInput" value="#{art.name}"  style="width:100%"/></f:facet>
       </p:cellEditor>
   </p:column>

   <p:column headerText="Budget">
       <p:cellEditor>
           <f:facet name="output"><h:outputText value="#{art.budget}" /></f:facet>
           <f:facet name="input"><p:inputText value="#{art.budget}" style="width:100%" label="Budget"/></f:facet>
       </p:cellEditor>
   </p:column>
   <p:column style="width:32px">

       <p:rowEditor  />
   </p:column>
  </p:dataTable>

and in the bean:

public void onRowEdit(RowEditEvent event ) {

    Article f =  (Article) event.getObject();

    formationFacade.update(f);
    FacesMessage msg = new FacesMessage("Article Edited", ((Article) event.getObject()).getName());
    FacesContext.getCurrentInstance().addMessage(null, msg);
}

I ve seen this : link but it doesn't work for me I get the old value after editing and I have no change in may database .. can someone help me please?

Community
  • 1
  • 1
Betty
  • 67
  • 1
  • 8
  • The code seems right, did you check the value of `Article f`? maybe do you have an error on `formationFacade.update(f);` code line? – giaffa86 Dec 12 '14 at 10:01
  • thanks @giaffa86 for your reply .. when I put a **System.out.println("budget de la formation :: : "+f.getBudget()); ** I get the old value and I don't think that the error is in the update method because it work fine if I don't use onRowEdit ..I m lost because I cant see where is my problem – Betty Dec 12 '14 at 10:04
  • Ok. Did you wrap your dataTable inside to `h:form`? This is the only problem that I see. You called your datatable "form", probably you wrong on this. Each input component must be inside a form – giaffa86 Dec 12 '14 at 10:11
  • Yes my dataTable is inside the `h:form`...even if I write a new value in the inputText it doesn't change anything..in fact the only difference I have from the primefaces showcases is that my dataTable is fill with a list of value from database and not a static one .. I don't know if I should do any change in this method ? – Betty Dec 12 '14 at 10:18
  • If `allArticles` is a properly setted as bean property, there aren't differences between static filling and dynamic filling. – giaffa86 Dec 12 '14 at 10:26
  • Try to put just `:form` on update attribute of rowEdit tag. – giaffa86 Dec 12 '14 at 10:29
  • I've just tried primefaces example showcase and it works well on Primefaces 5.1, JSF Mojarra 2.2.7 . If do you change datamodel something good happens? Maybe you have some faces config property that made a conflict with normal behaviour. Can you also test primefaces showcase example? – giaffa86 Dec 12 '14 at 11:33
  • @giaffa86 I just tried primefaces example showcase and also it work fine .. I actually use primefaces 5.0 ,JSF2.2 with Jboss 7. – Betty Dec 12 '14 at 12:17
  • Really weird, try to start from primefaces example and recreate your situation changing only the datamodel and `OnRowEdit` method. – giaffa86 Dec 12 '14 at 13:31
  • its exactly what I ve did .. I don't know if I should add somthing else in addition to `em.merge` in my update method O.o ? – Betty Dec 12 '14 at 13:41
  • I don't know what your update method do. But it's not important if `f` doesn't have updated values (before to pass it to update method). – giaffa86 Dec 12 '14 at 13:44

3 Answers3

0

There's one thing that is strange/wrong, that may or may not be the cause of your issues, but I would recommend fixing. From this update=":form:msgs" I assume that you have an enclosing tags like <h:form id="form"><p:growl id="msgs". On the other hand you repeat the id="form" inside <p:dataTable id="form". Repeating the id is surely wrong, but I'm not sure if its the cause of your issue

Master Slave
  • 27,771
  • 4
  • 57
  • 55
0

first, you have to provide the EditMode parameter with the value of

CellEdit

or RowEdit as your case.

second, you can do edit like this without event if you want a simple way to edit data table is

modifyYourModel(Model x){
// call your function to modify 
}

and in the data table, you can do that

<p:dataTable id="tab" var="art" value="#{myMB.allArticles}" editable="true" EditMode="rowEdit" style="margin-bottom:20px">
   <f:facet name="header">

   </f:facet>

   <p:ajax event="rowEdit" listener="#{myMB.modifyYourModel(art)}" update=":form:msgs" />
   <p:ajax event="rowEditCancel" listener="#{myMB.onRowCancel}" update=":form:msgs" />
Zouhair Kasmi
  • 614
  • 2
  • 6
  • 13
0

Use your IDs instead of :form, :msgs.

<p:ajax event="rowEdit" listener="#{myMB.onRowEdit}" update="messages tab" />
<p:ajax event="rowEditCancel" listener="#{myMB.onRowCancel}" update="messages tab" />

Also you have to update list "allArticles" by edited object.

Martin Volek
  • 315
  • 2
  • 13
  • :form:msgs IS an id... It is the full absolute client id which is needed if you go to the up in the component tree to update something. So that part in the question is good and hence that part of your answer is sort of not. – Kukeltje Aug 13 '19 at 08:58
  • But that does not works for me (Primefaces 7.0). I tried it now and answer sounds: "javax.servlet.ServletException: Cannot find component for expression ":form:msgs" referenced from"datatable_id" – Martin Volek Aug 13 '19 at 12:20
  • Yes, but than you don't have components in your page with id's that result in this clientId. And that is not uncommon, everybody picks his or hers own id's https://stackoverflow.com/questions/8634156 – Kukeltje Aug 13 '19 at 13:13