开发者

PrimeFaces DataTable - Filtering (problem running the example)

开发者 https://www.devze.com 2023-03-24 20:22 出处:网络
I am trying this example in PrimeFaces. I understand only the first few lines of the code. <p:dataTable var=\"car\" value=\"#{tableBean.carsSmall}\"

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 sear开发者_如何学运维ch 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消