-1

我有奇怪的情况对象

  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
4

1 回答 1

-1

好的,我得到合同中的字段是私有的,所以在我编码的方式中我无法访问它们

如何读取 Java 中的私有字段?

解决了

于 2013-11-07T11:31:04.530 回答