0

I try to update a datatable row with PrimeFaces 3.1.1 but it makes all values null.

 public void onRowEdit(RowEditEvent event) {
    Client us= (Client) event.getObject();
    System.out.println("event edit"+us);
    clientService.editClient( us );

    FacesMessage msg = new FacesMessage("Client modifié", ((Client) event.getObject()).getName_customer());
    FacesContext.getCurrentInstance().addMessage(null, msg);
}

This is my page xhtml:

 <h:form>
 <p:dataTable var="client" value="#{clientBean.clients}" widgetVar="clientTable" emptyMessage="No customers found with given criteria" filteredValue="#{clientBean.filteredClients}" paginator="true" rows="10" rowsPerPageTemplate="5,10,15"  editable="true" id="testContainer">
 <p:ajax event="rowEdit" update="@this" listener="#{clientBean.onRowEdit(event)}"  />
 <f:facet name="header"><p:outputPanel><h:outputText value="Recherche d'un client:" /> </p:outputPanel>
 </f:facet>
 <p:column filterBy="#{client.user.username}" headerText="Collaborateur"  filterMatchMode="contains">
 <h:outputText value="#{client.user.username}" />
  </p:column>
 <p:column filterBy="#{client.name_customer}" headerText="Nom"  filterMatchMode="contains">
  <f:facet name="output">
<h:link outcome="CustomerDetails?faces-redirect=true&amp;includeViewParams=true"  value="#{client.name_customer}"  >
<f:param  name="idCustomer" value="#{client.costumer_id}"></f:param>
 <f:param  name="nameCustomer" value="#{client.name_customer}"></f:param>
</h:link> </f:facet>
<f:facet name="input"><p:inputText  value="#{client.name_customer}"/></f:facet>
</p:cellEditor> 
</p:column>
<p:column filterBy="#{client.statut}" headerText="Statut"  filterMatchMode="contains">
5
  • Is this listener method invoked by the rowEdit event? How do you invoke the rowEdit event in <p:dataTable>?
    – Tiny
    Aug 7, 2014 at 15:03
  • <p:ajax event="rowEdit" update="@this" listener="#{clientBean.onRowEdit}" />
    – Zeineb
    Aug 7, 2014 at 15:06
  • Do you really have the property name_customer in your Client model? The name does not follow the general naming convention. It should look something like nameCustomer (it should not be a probelm though).
    – Tiny
    Aug 7, 2014 at 15:19
  • yes I have the property name_customer in my model and it is no problem in the case of adding a Client
    – Zeineb
    Aug 7, 2014 at 15:24
  • Is the Client object the field being modified or does it represent a row in your datatable? If it represents a row you might want to look into RowEditEvent.getObject().getSoure()
    – Yannick
    Aug 7, 2014 at 18:55

1 Answer 1

0

the problem is that your object Client us is null , try to display a property from your object us if is null so that will confirm that you don't get your object from your page correctly . So i suggest you to replace that :

<p:ajax event="rowEdit" update="@this" listener="#{clientBean.onRowEdit}" />

with that

<p:ajax event="rowEdit" update="@this" listener="#{clientBean.onRowEdit(event)}" />

Note that i just added the event property to onRowEdit.

2
  • when i add event property to onRowEdit, i have this exception: javax.el.ELException: /pages/newCostumer.xhtml @76,85 listener="#{clientBean.onRowEdit(event)}": java.lang.NullPointerException at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111) at org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:42)
    – Zeineb
    Aug 7, 2014 at 15:33
  • can you post your page xhtml ? Aug 7, 2014 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.