1
votes

I'm trying to edit row data in primfaces dataTable but not working I try the same code of primefaces showcases in below link

http://www.primefaces.org/showcase/ui/data/datatable/edit.xhtml

my jsf page

<h:form id="form">
        <p:dataTable id="depTable" value="#{departmentBean.departments}"
            var="dep" editable="true">

            <f:facet name="header">
                All departments
            </f:facet>
            <p:ajax event="rowEdit" listener="#{departmentBean.onRowEdit}"
                update=":form:depTable" />
            <p:ajax event="rowEditCancel"
                listener="#{departmentBean.onRowCancel}" update=":form:depTable" />

            <p:column headerText="Id">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{dep.id}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText id="modelInput" value="#{dep.id}" style="width:100%" />
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="Name">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{dep.name}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{dep.name}" style="width:100%" />
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column style="width:32px">
                <p:rowEditor />
            </p:column>
        </p:dataTable>
    </h:form>

and method in bean

public void onRowEdit(RowEditEvent event) {
    System.out.println(((Department) event.getObject()).getName());
    FacesMessage msg = new FacesMessage("Car Edited",
            ((Department) event.getObject()).getName());
    FacesContext.getCurrentInstance().addMessage(null, msg);
}

public void onRowCancel(RowEditEvent event) {
    FacesMessage msg = new FacesMessage("Edit Cancelled",
            ((Department) event.getObject()).getName());
    FacesContext.getCurrentInstance().addMessage(null, msg);
}

I'm using primfaces 4.0

3
What do you mean by "not working"? How is it not working?kolossus
not update the table with new values of row . it saved the old values to the row. thanks for your helpKarim Saad

3 Answers

1
votes

In my case it was the problem that my backing bean was @SessionScoped (in PF example it is @ViewScoped) so I need to modify dataTabe value:

 <p:dataTable id="settingsTbl" value="#{settingsBean.settingsList}" var="item" editable="true">

.....

 public List<Settings> getSettingsList() {  
    if(settingsList==null){
        settingsList = settingsFacade.findAll();
    }
    return settingsList;
}
0
votes

I had encountered this issue and my workaround was to put the dataTable within a Form.

-1
votes

https://plnkr.co/edit/nYxHfY8PsGH586Om?open=lib%2Fscript.js

<div ng-controller="MainCtrl">
    <div ui-grid="gridOptions" ui-grid-edit ui-grid-row-edit ui-grid-cellNav class="grid"> 
       </div>
    <button id='flushDirty' ng-click='flushDirty()'>Flush Dirty</button>
      <button id='addRow' ng-click='addRow()'>Add Row</button>
  <br/>
  
  <p>Dirty rows: {{dirtyRows.length}}</p>

  <div ng-repeat="row in dirtyRows">
    {{row.entity.id}}, {{row.entity.gender}}
  </div>
</div>