p:dataTable过滤不适用于模板

时间:2014-12-24 18:09:23

标签: jsf jsf-2 primefaces datatable

我正在尝试使用PrimeFaces框架创建过滤数据表。 我的问题是显示数据表但过滤选项不起作用,请帮助!

我的page.xhtml看起来像:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <ui:composition>
        <h5>
            <h:form>
                <p:dataTable var="student" value="#{studentWizard.students}" widgetVar="studentTable" emptyMessage="Aucun élève trouvé" id="tableStudent" filteredValue="#{studentWizard.filteredStudents}" >

                    <f:facet name="header">
                        <p:outputPanel>
                            <h:outputText value="Chercher tous les champs:" />
                            <p:inputText id="globalFilter" onkeyup="studentTable.filter()" style="width:150px" placeholder="Entrer le mot-clé"/>
                        </p:outputPanel>
                    </f:facet>

                    <p:column filterBy="#{student.studentCode}"  headerText="Code de l'élève" filterMatchMode="contains">
                        <h:outputText value="#{student.studentCode}"/>
                    </p:column>

                    <p:column filterBy="#{student.firstName}" headerText="Prénom" filterMatchMode="contains">
                        <h:outputText value="#{student.firstName}"/>
                    </p:column>

                    <p:column filterBy="#{student.lastName}" headerText="Nom" filterMatchMode="contains">
                        <h:outputText value="#{student.lastName}"/>
                    </p:column>

                    <p:column headerText="Modifier" >
                        <p:commandButton value="Modifier" type="submit"  ajax="false"  icon="ui-icon-update"/>
                    </p:column>
                </p:dataTable>
            </h:form>
        </h5>
    </ui:composition>
</html>

和我的Java Bean:

@ManagedBean(name="studentWizard")
@Component
@ViewScoped
public class StudentWizard implements Serializable {

    public StudentWizard() {}

    private static final long serialVersionUID = 1L;

    private Student student;
    private List<Student> students;
    private List<Student> filteredStudents;

    @PostConstruct
    public void init() {
        students = getAllStudent();
    }

    public List<Student> getFilteredStudents() {
        return filteredStudents;
    }

    public void setFilteredStudents(List<Student> filteredStudents) {
        this.filteredStudents = filteredStudents;
    }

    @Autowired
    private StudentManager studentManager;

    public void setStudentManager(StudentManager studentManager) {
        this.studentManager = studentManager;
    }

    public Student getstudent() {
        return student;
    }

    public StudentManager getStudentManager() {
        return studentManager;
    }

    public void setstudent(Student student) {
        this.student = student;
    }

    public void save() {
        studentManager.saveStudent(student);
        student = new Student();

    }

    public List<Student> getAllStudent() {
        return studentManager.getAllStudent();
    }

    public Student getStudentById(int id) {
        return studentManager.getStudentById(id);
    }

    public List<Student> getStudents() {
        return students;
    }

    public void setStudents(List<Student> students) {
        this.students = students;
    }
}

这是我的主页

<h:body>
<p:layout style="min-width:400px;min-height:100px;">
<p:layoutUnit position="center" size="400"  >
</p:layoutUnit>
</p:layout>
<p:layout style="min-width:400px;min-height:500px;">
<p:layoutUnit position="west" size="244"  >
 <h5>       
<h:form>
   <p:menu toggleable="true">
     <p:submenu label="Eleves">
        <p:menuitem value="Nouvel élève" action="#{menuView.setSelectedItem(1)}"       update=":globalPanel"  />
        <p:menuitem value="Consultation" action="#{menuView.setSelectedItem(2)}" update=":globalPanel" />
    </p:submenu>
     <p:submenu label="Personnels">
     </p:submenu>
     <p:submenu label="Notes">
    </p:submenu>
     <p:submenu label="Caisses">
     </p:submenu>
    <p:submenu label="Salaires">
     </p:submenu>
    <p:submenu label="Référentiel">
     </p:submenu>
 </p:menu>
 </h:form>
</h5>
</p:layoutUnit>
<p:layoutUnit position="center">
<h:panelGroup id ="globalPanel"  >
    <h:panelGroup id="inscriptionPanel" rendered="#{menuView.selectedItem == 1}" header="Inscription" style="margin-bottom:20px">
    <ui:include src="/inscription.xhtml" />
    </h:panelGroup>  
    <h:panelGroup id="testerPanel" rendered="#{menuView.selectedItem == 2}" header="Consultation" style="margin-bottom:20px"  >
    <ui:include src="/consul.xhtml" />
    </h:panelGroup>
</h:panelGroup>
</p:layoutUnit>
</p:layout>
</h:body>

0 个答案:

没有答案