简体   繁体   English

Primefaces 4.0数据表Filterby不过滤数据

[英]Primefaces 4.0 datatable Filterby not filtering data

I've got an orderBy to work, but my FilterBy does nothing. 我有一个orderBy可以工作,但是我的FilterBy不执行任何操作。 Symptoms: No messages, and all rows still show up. 症状:没有消息,并且所有行仍然显示。 Neither the column's filter, nor the global filter work. 列的过滤器或全局过滤器都不起作用。 Sometimes typing in the filter box causes the table to reload in its original order (after a page refresh). 有时在过滤器框中键入内容会导致表以其原始顺序(在刷新页面后)重新加载。

The project uses JPA 2.0, EJB 3.0, PrimeFaces 4.0, Facelets. 该项目使用JPA 2.0,EJB 3.0,PrimeFaces 4.0,Facelets。 My UserDAO extends an abstract DAOService. 我的UserDAO扩展了一个抽象DAOService。

Any help would be much appreciated. 任何帮助将非常感激。

I've looked at the Primefaces 4.0 documentation, and the Primefaces website's DataTable filterBy example; 我看了Primefaces 4.0文档,以及Primefaces网站的DataTable filterBy示例; I've also searched StackOverflow and google. 我还搜索了StackOverflow和Google。 I can't figure out where I've gone wrong. 我无法弄清楚哪里出了问题。

xhtml page: xhtml页面:

<!-- Define Facelet Template -->
<ui:composition template="/WEB-INF/templates/template.xhtml">

<!-- Header defined in template -->

<!-- Body overrides template -->
<ui:define name="content">
    <f:view>
        <h:body>
            <h:outputStylesheet name="css/styles.css" />
            <p:dataTable id="dataTable" widgetVar="usersTable" var="user"
                value="#{users.all}" emptyMessage="none found"
                filteredValue="#{users.filteredUsers}" editable="true"
                editMode="cell" rowKey="user.id">
                <f:facet name="header">
                    <p:outputPanel>
                        <h:outputText value="Search all fields:" />
                        <p:inputText id="globalFilter" onkeyup="usersTable.filter()"
                            style="width:150px" />
                    </p:outputPanel>
                    <!-- <h:outputText>Users</h:outputText> -->
                </f:facet>
                <p:column id="idColumn" headerText="ID" sortBy="id"
                    filterBy="#{user.id}">
Edit: I have also tried filterBy="id" to no avail.
                        <h:outputText value="#{user.id}" />
                </p:column>
                ... more columns like that ...
                <f:facet name="footer">This is a footer</f:facet>
            </p:dataTable>
        </h:body>
    </f:view>
</ui:define>
<!-- Footer defined in template -->
</ui:composition>

UserController.java: UserController.java:

import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import model.security.dao.UserDAORemote;
import model.security.jpa.TSEC_User;

//Accessible to jsf page as "users"
@ManagedBean(name="users")
@SessionScoped
public class UserController implements Serializable {
private static final long serialVersionUID = 1L;

@EJB // // Injects the UserDAO session bean using the @EJB annotation
UserDAORemote model;

private List<TSEC_User> all;
private List<TSEC_User> filteredUsers;

public UserController() {}

@PostConstruct
public void init() {
    all = model.find();
}
public List<TSEC_User> getAll() {
    return all;
}
public void setAll(List<TSEC_User> all) {
    this.all = all;
}

public List<TSEC_User> getFilteredUsers() {
    return filteredUsers;
}
public void setFilteredUsers(List<TSEC_User> filteredUsers) {
    this.filteredUsers = filteredUsers;
}
}

My template.xhtml file used <head> and <body> tags instead of <h:head> and <h:body> tags. 我的template.xhtml文件使用<head><body>标记而不是<h:head><h:body>标记。 Changing these to their JSF equivalents allowed PrimeFaces to filter my DataTable. 将这些更改为与它们的JSF等效项可以使PrimeFaces过滤我的DataTable。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM