Primefaces数据表:这是不工作的



我试图在primfaces dataTable中编辑行数据,但不工作我在下面的链接

中尝试了相同的素面代码。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>

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

我使用primfaces 4.0

在我的情况下,这是我的问题,我的支持bean是@SessionScoped(在PF的例子是@ViewScoped),所以我需要修改数据表值:

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

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

我遇到了这个问题,我的解决办法是把dataTable在一个表单中

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>

相关内容

  • 没有找到相关文章

最新更新