简体   繁体   中英

PrimeFaces DataTable - Filtering (problem running the example)

I am trying this example in PrimeFaces . I understand only the first few lines of the code.

<p:dataTable var="car" value="#{tableBean.carsSmall}"
    emptyMessage="No cars found with given criteria">

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

It could display a search box here. The reaming lines of code would be to add the column and populate the columns with data. I don't understand what

<p:column filterBy="#{car.model}" 
    headerText="Model" footerText="contains"
    filterMatchMode="contains">
    <h:outputText value="#{car.model}" />
</p:column>`

What is #{car.model} ? it doesn't specify anything call model in the java class. How do I alter my java class to make a column display?

The expression variable car is declared to be the var attribute of the dataTable. This means that each unique row in the dataTable component can be referenced in expression language by the variable car .

The model property of car is a Bean property of the Serializable POJO Car. It is assumed that the Car class has a property model meaning a getter getModel() and a setter setModel() .

The filterBy attribute of <p:column> specifies that this column header will have its own unique filter text field and that it will filter the rows on car.model property.

The attribute filterMatchMode specifies that the match criteria is contains which means any textual occurence of what is typed into the column filter field will equate as a matched record. See the Primefaces Guide for a complete list of filterMatchMode options.

private List<Car> carsSmall;

carsSmall is a list that contains Car objects. Car is imported here:

import org.primefaces.examples.domain.Car; 

Car.java Source

Car is the backing bean, it has an attribute model that contains the car's model as a String .

In car #{car.model} is defined here:

<p:dataTable var="car"...>

The dataTable iterates over every element in the list carsSmall and you can access the current element using the name given in the var attribute (here: car ). So #{car.model} calls the getModel() method of the current Car object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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