-1

i have strange situation the object

  contract 

in the method

  load 

seems to no have fields why??

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;
    }
}
}

this is strange because the line:

    System.out.println("load: " + contract.getUniqueRowID());

print me the right value.

but

    System.out.println(contract.getClass().getFields()[0].getName());

give me:

    ArrayoutofboundExpcetion 

this means there are no fields.

   public class Contract implements Serializable
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
FrankTan
  • 1,626
  • 6
  • 28
  • 63

1 Answers1

-1

Ok i got the fields in Contract are private so in the way i coded i could not access to them

How do I read a private field in Java?

solved

Community
  • 1
  • 1
FrankTan
  • 1,626
  • 6
  • 28
  • 63