我正在使用使用 LazyDataModel 的 primefaces 4.0 数据表。我也在使用<p:rowEditor />
and 当一行被编辑和保存时,我的数据表数据没有被更新。似乎在 ajax 更新时没有调用 LazyDataModel.load 方法。
有什么我做错了或解决方法吗?这是一个已知问题吗?
LazyUserDataModel.java
public class LazyUserDataModel extends LazyDataModel<User> {
private static final long serialVersionUID = -7759670987463023731L;
private List<User> users;
private Dao dao;
private String username;
private List<String> roles;
public LazyUserDataModel(Dao dao, String username, List<String> roles) {
this.dao = dao;
this.username = username;
this.roles = roles;
}
@Override
public List<User> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {
List<User> users = new ArrayList<User>();
users = dao.findAllUsers(username, roles, first, pageSize);
...
UserGroupBacking.java
...
private LazyDataModel<User> users;
@PostConstruct
public void init() {
this.ds = databaseBacking.getDs();
if(isLoggedIn()) {
loadData();
}
}
public void updateUsersGroups(RowEditEvent event) {
// Save data to db (this part works fine)
loadData();
}
private void loadData() {
Dao dao = new Dao(ds);
users = new LazyUserDataModel(dao, accessBacking.getUsername(), accessBacking.getRoles());
}
...
.xhtml
<p:tabView id="tabs">
<p:tab id="userTab" title="Users">
<h:form id="userForm">
<p:growl for="growl" severity="info" autoUpdate="true" showDetail="true" />
<p:messages id="userMessages" severity="error" showDetail="true" />
<p:dataTable var="user" value="#{userGroupBacking.users}" editable="true" id="userTable" paginator="true" rows="20"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" lazy="true"
filteredValue="#{userGroupBacking.filteredUsers}" >
<p:ajax event="rowEdit" listener="#{userGroupBacking.updateUsersGroups}" update=":tabs:userForm:userTable, :tabs:userForm:userMessages" />
<p:column headerText="User" filterBy="#{user.name}" filterMatchMode="contains">
<h:outputText value="#{user.name}" />
</p:column>
<p:column headerText="Groups">
<p:cellEditor>
<f:facet name="output">
<ui:repeat var="group" value="#{user.groups}">
<h:outputText value="#{group.name}" /><br />
</ui:repeat>
</f:facet>
<f:facet name="input">
<p:selectCheckboxMenu value="#{user.groupsAsString}" label="Groups" filter="true" filterText="Filter" filterMatchMode="contains">
<f:selectItems value="#{userGroupBacking.groupsAsSelectItems}" />
</p:selectCheckboxMenu>
</f:facet>
</p:cellEditor>
</p:column>
...