Primefaces 数据表过滤器不起作用 [英] Primefaces datatable filter doesn't work

查看:14
本文介绍了Primefaces 数据表过滤器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须做一些根本错误的事情,我使用数据表将代码精简到最低限度,并启用了一个列过滤器和一个全局过滤器.

I must do something fundamentally wrong, I stripped down the code to the bare minimum with a data table and enabling one column filter and a globe filter.

有趣的是来自 Primefaces 的示例代码有效.与我的代码的唯一区别应该是它从数据库收集数据,而不是在 bean 中生成数据.

The funny thing is that the example code from Primefaces works. The only difference to my code should be that it gathers data from a DB rather than generating it in the bean.

当我在过滤器中输入某些内容时,我不知道为什么我的示例没有执行任何操作,如果您有任何想法,我将不胜感激.

I have no more clues why my example doesn't do anything when I type something in the filter would be appreciate any ideas here.

我的 xhtml:

    <!DOCTYPE html>
<html xmlns="http://www.w3c.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

<ui:composition template="layout.xhtml">

    <ui:define name="title">All Projects</ui:define>    

    <ui:define name="content">


        <p:dataTable var="project" value="#{projectController.allProjects}" widgetVar="projectTable" filteredValue="#{projectController.filteredProjects}">

            <f:facet name="header">
                <p:outputPanel>  
                    <h:outputText value="Search all fields:" />  
                    <p:inputText id="globalFilter" onkeyup="PF('projectTable').filter()" style="width:150px" />  
                </p:outputPanel>
            </f:facet>

            <p:column headerText="Name" filterBy="#{project.name}">
                <h:outputText value="#{project.name}" />
            </p:column>

            <p:column headerText="Priority">
                <h:outputText value="#{project.priority}" />
            </p:column>

            <p:column headerText="Exit">
                <h:outputText value="#{project.exitCriteria}" />
            </p:column>

        </p:dataTable>      

    </ui:define>
</ui:composition>

我的豆子:

    package com.apa.projectd.common;
    import java.io.Serializable;
    import java.util.List;
    import javax.annotation.PostConstruct;
    import javax.enterprise.context.SessionScoped;
    import javax.faces.bean.ManagedBean;
    import javax.inject.Inject;
    import com.habony.common.Loggable;
    import com.habony.projectd.ejbs.ProjectEJB;
    import com.habony.projectd.enteties.Project;

    @ManagedBean(name="projectController")
    @SessionScoped
    @Loggable
    public class ProjectController implements Serializable{

private static final long serialVersionUID = 8345760187637787728L;

@Inject
private ProjectEJB projectEJB;

private List<Project> filteredProjects;
private List<Project> allProjects;

@PostConstruct
public void loadAllProjects(){
    allProjects =  projectEJB.getAllProjects();
}

//
// Getters and Setters
//
public List<Project> getFilteredProjects() {
    return filteredProjects;
}

public void setFilteredProjects(List<Project> filteredProjects) {
    this.filteredProjects = filteredProjects;
}

public void setAllProjects(List<Project> allProjects) {
    this.allProjects = allProjects;
}

public List<Project> getAllProjects(){
    return allProjects;
}

}

推荐答案

p:dataTable 的过滤器特性需要包含在 标签中才能正常工作.修改后的代码 xhtml 将:

The filters features of p:dataTable need to be wrapped in <h:form> tags for work fine. The code xhtml modified would:

<!DOCTYPE html>
<html xmlns="http://www.w3c.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

<ui:composition template="layout.xhtml">

    <ui:define name="title">All Projects</ui:define>    

    <ui:define name="content">
       <h:form>
           <p:dataTable var="project" value="#{projectController.allProjects}" widgetVar="projectTable" filteredValue="#{projectController.filteredProjects}">

              <f:facet name="header">
                <p:outputPanel>  
                    <h:outputText value="Search all fields:" />  
                    <p:inputText id="globalFilter" onkeyup="PF('projectTable').filter()" style="width:150px" />  
                 </p:outputPanel>
              </f:facet>

              <p:column headerText="Name" filterBy="#{project.name}">
                 <h:outputText value="#{project.name}" />
              </p:column>

              <p:column headerText="Priority">
                 <h:outputText value="#{project.priority}" />
              </p:column>

             <p:column headerText="Exit">
                 <h:outputText value="#{project.exitCriteria}" />
             </p:column>

          </p:dataTable>      
      </h:form>
   </ui:define>
</ui:composition>

这篇关于Primefaces 数据表过滤器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆