我的对象很奇怪
contract
方法
load
似乎没有字段为什么?
public class LazyContractDataModel extends LazyDataModel<Contract>{
/**
*
*/
private static final long serialVersionUID = -9001840760481920608L;
private List<Contract> datasource;
public LazyContractDataModel(List<Contract> datasource) {
this.datasource = datasource;
}
@Override
public Contract getRowData(String rowKey) {
for(Contract Contract : datasource) {
if(Contract.getUniqueRowID().equals(rowKey))
return Contract;
}
return null;
}
@Override
public Object getRowKey(Contract Contract) {
return Contract.getUniqueRowID();
}
@Override
public List<Contract> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {
System.out.println("load Data");
List<Contract> data = new ArrayList<Contract>();
//filter
for(Contract contract : datasource) {
boolean match = true;
for(Iterator<String> it = filters.keySet().iterator(); it.hasNext();) {
try {
System.out.println("filters");
String filterProperty = it.next();
System.out.println("filterProperty: " + filterProperty);
String filterValue = filters.get(filterProperty);
System.out.println("filterValue: " + filterValue);
System.out.println("load: " + contract.getUniqueRowID());
System.out.println(contract.getClass().getFields()[0].getName());
System.out.println(contract.getClass().getField(filterProperty).getName());
String fieldValue = String.valueOf(contract.getClass().getField(filterProperty).get(contract));
System.out.println("fieldValue: " + fieldValue);
if(filterValue == null || fieldValue.startsWith(filterValue)) {
match = true;
}
else {
match = false;
break;
}
} catch(Exception e) {
System.out.println("filters exception");
System.out.println(e);
match = false;
}
}
System.out.println(match);
if(match) {
data.add(contract);
}
}
//sort
if(sortField != null) {
Collections.sort(data, new LazySorter(sortField, sortOrder));
}
//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;
}
}
}
这很奇怪,因为行:
System.out.println("load: " + contract.getUniqueRowID());
给我打印正确的价值。
但是
System.out.println(contract.getClass().getFields()[0].getName());
告诉我:
ArrayoutofboundExpcetion
这意味着没有字段。
public class Contract implements Serializable