编辑p:dataTable中的行

时间:2014-08-07 14:49:30

标签: jsf primefaces

我尝试使用PrimeFaces 3.1.1更新数据表行,但它使所有值都为空。

 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);
}

这是我的页面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">

1 个答案:

答案 0 :(得分:0)

问题是您的对象客户端我们为空,尝试显示对象我们的属性,如果为null,则会确认您没有获取您的对象正确地从您的页面。所以我建议你替换它:

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

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

请注意,我刚刚将事件属性添加到onRowEdit。