When using JSF primefaces, in Java Unreadable property on lang.string type
                                        
                    •
                    Java                                    
                I'm trying to use the demo code in the site to implement deferred loading data in the data table
PrimeFaces Lazy loading
I received an error
javax.el.PropertyNotFoundException: /table.xhtml @14,49 value="#{car.year}": Property 'year' not readable on type java.lang.String
This is my table XHTML code
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui">
    <h:form id="form">  
<p:dataTable var="car" value="#{tableBean.lazyModel}" paginator="true" rows="10"  
              id="carTable" lazy="true">  
    <p:column headerText="Year" sortBy="year" filterBy="#{car.year}">  
        <h:outputText value="#{car.year}" />  
    </p:column>  
    <p:column headerText="Color" sortBy="color" filterBy="#{car.color}">  
        <h:outputText value="#{car.color}" />  
    </p:column>  
</p:dataTable>
Tablebean code
@ManagedBean
public class TableBean {  
private LazyDataModel<Car> lazyModel;  
private List<Car> cars;
public TableBean() {
    System.out.println("Girish");
    cars = populateRandomCars(50);
    lazyModel = new LazyCarDataModel(cars);
    lazyModel.setRowCount(10);
}
public LazyDataModel<Car> getLazyModel() {
    return lazyModel;
}
public void setLazyModel(LazyDataModel<Car> lazyModel) {
    this.lazyModel = lazyModel;
}
public List<Car> getCars() {
    return cars;
}
public void setCars(List<Car> cars) {
    this.cars = cars;
}
private List<Car> populateRandomCars( int size) {
    List<Car> list = new ArrayList<Car>();
    Car car = null;
    for(int i = 0 ; i < size ; i++) {
        car = new Car();
        car.setColor("color "+i);
        car.setYear(""+i);
        list.add(car);  
    }
    return list;
}  
}
Car code
class Car {
private String year;
private String color;
public String getYear() {
    return year;
}
public void setYear(String year) {
    this.year = year;
}
public String getColor() {
    return color;
}
public void setColor(String color) {
    this.color = color;
}
}
And lazycardatamodel code
public class LazyCarDataModel extends LazyDataModel<Car> {  
/**
 * 
 */
private static final long serialVersionUID = 1L;
private List<Car> datasource;  
public LazyCarDataModel(List<Car> datasource) {  
    this.datasource = datasource;  
}  
@Override  
public Car getRowData(String rowKey) {  
    return new Car();  
}  
@Override  
public Object getRowKey(Car car) {  
    return car.getYear();  
}  
@Override  
public List<Car> load(int first,int pageSize,String sortField,SortOrder sortOrder,Map<String,String> filters) {  
    List<Car> data = new ArrayList<Car>();  
    //filter  
    for(Car car : datasource) {  
        boolean match = true;  
        for(Iterator<String> it = filters.keySet().iterator(); it.hasNext();) {  
            try {  
                String filterProperty = it.next();  
                String filterValue = filters.get(filterProperty);  
                String fieldValue = String.valueOf(car.getClass().getField(filterProperty).get(car));  
                if(filterValue == null || fieldValue.startsWith(filterValue)) {  
                    match = true;  
                }  
                else {  
                    match = false;  
                    break;  
                }  
            } catch(Exception e) {  
                match = false;  
            }   
        }  
        if(match) {  
            data.add(car);  
        }  
    }  
    //rowCount  
    int dataSize = data.size();  
    this.setRowCount(dataSize);  
    //paginate  
    if(dataSize > pageSize) {  
        try {  
            return data.subList(first,first + pageSize);  
        }  
        catch(indexoutofboundsexception e) {  
            return data.subList(first,first + (dataSize % pageSize));  
        }  
    }  
    else {  
        return data;  
    }  
}  
}
Please help.
Thank you in advance
Solution
Model class, in which case car must be public
                            The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
                        
                                            
                        THE END
                    
                    
                    
                                                        二维码
                        
                        
                                                
                        