我试图在primfaces dataTable中编辑行数据但不能正常工作 我在下面的链接
中尝试相同的primefaces陈列代码http://www.primefaces.org/showcase/ui/data/datatable/edit.xhtml
我的jsf页面
<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
答案 0 :(得分:1)
在我的情况下,问题是我的支持bean是@SessionScoped(在PF示例中它是@ViewScoped)所以我需要修改dataTabe值:
<p:dataTable id="settingsTbl" value="#{settingsBean.settingsList}" var="item" editable="true">
.....
public List<Settings> getSettingsList() {
if(settingsList==null){
settingsList = settingsFacade.findAll();
}
return settingsList;
}
答案 1 :(得分:0)
我遇到了这个问题,我的解决方法是将dataTable放在窗体中。
答案 2 :(得分:-1)
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>