rowSelectListener="#{bean.method}" throws javax.el.ELException: class 'com.example.Bean' 没有 属性 'method'

rowSelectListener="#{bean.method}" throws javax.el.ELException: The class 'com.example.Bean' does not have the property 'method'

我将 PrimeFaces JAR 库从版本 2 更改为版本 5,现在出现此异常。

javax.servlet.ServletException: /home.xhtml: The class 'com.primefaces.sample.UserManagedBean' does not have the property 'onUserSelect'. javax.faces.webapp.FacesServlet.service(FacesServlet.java:606) root cause

javax.el.ELException: /home.xhtml: The class 'com.primefaces.sample.UserManagedBean' does not have the property 'onUserSelect'.

xhtm 页面包含 p:datatable

rowSelectListener="#{userManagedBean.onUserSelect}"
rowUnselectListener="#{userManagedBean.onUserUnselect}"

豆子:

public void onUserSelect(SelectEvent event) {
    selectedUser = (User) event.getObject();
    System.out.println("selectedUser = " + selectedUser);
}

public void onUserUnselect(UnselectEvent event) {
    selectedUser = null;
}

那么,为什么这对 PrimeFaces 5 不起作用,而对 PrimeFaces 2 版本起作用呢?

如果勾选Primefaces 5 user guide, you'll notice that you cannot find the rowSelectListener attribute anywhere, but it existed in Primefaces 2. Perhaps you want to take a look at the onRowSelect and onRowUnselect listeners of <p:ajax> events for rowSelect and rowUnselect (page 167 of Primefaces 5 user guide). See here also: Primefaces tag rowSelectListener not found.