简体   繁体   English

PrimeFaces DataTable - 过滤(运行示例的问题)

[英]PrimeFaces DataTable - Filtering (problem running the example)

I am trying this example in PrimeFaces . 在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} ? 什么是#{car.model} it doesn't specify anything call model in the java class. 它没有在java类中指定任何调用model How do I alter my java class to make a column display? 如何更改我的java类以显示列?

The expression variable car is declared to be the var attribute of the dataTable. 表达式变量car被声明为dataTable的var属性。 This means that each unique row in the dataTable component can be referenced in expression language by the variable car . 这意味着dataTable组件中的每个唯一行都可以由变量car以表达式语言引用。

The model property of car is a Bean property of the Serializable POJO Car. carmodel属性是Serializable POJO Car的Bean属性。 It is assumed that the Car class has a property model meaning a getter getModel() and a setter setModel() . 假设Car类具有属性model意味着getter getModel()和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. <p:column>filterBy属性指定此列标题将具有其自己的唯一过滤器文本字段,并且它将过滤car.model属性上的行。

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. 属性filterMatchMode指定匹配条件contains ,这意味着列入过滤器字段的内容的任何文本出现将等同为匹配记录。 See the Primefaces Guide for a complete list of filterMatchMode options. 有关filterMatchMode选项的完整列表,请参阅Primefaces指南。

private List<Car> carsSmall;

carsSmall is a list that contains Car objects. carsSmall是一个包含Car对象的列表。 Car is imported here: Car进口到这里:

import org.primefaces.examples.domain.Car; 

Car.java Source Car.java来源

Car is the backing bean, it has an attribute model that contains the car's model as a String . Car是支持bean,它有一个属性model ,包含汽车的模型作为String

In car #{car.model} is defined here: 汽车#{car.model}在这里定义:

<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 ). dataTable迭代列表carsSmall中的每个元素,您可以使用var属性(here: car )中给出的名称访问当前元素。 So #{car.model} calls the getModel() method of the current Car object. 所以#{car.model}调用当前Car对象的getModel()方法。

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

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