我想知道在某种程度上是否可以使lazyDataModel类型的sortField安全(类似于criteriaBuilder的MetaModel ..)。
LazyDataModel的方法具有以下方法签名:
@Override
public List<Visit> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
...
}
sortField是一个String ..想象一下以下情况:
class Book { private Cover cover; }
class Cover { private String pictureName; }
然后我想输入类似的内容:
@Override
public List<Visit> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
switch (sortField) {
case CoverPF_.pictureName:
// sort on pictureName
}
}
而不是(容易出错...):
@Override
public List<Visit> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
switch (sortField) {
case "cover.pictureName":
// sort on pictureName
}
}
Primefaces 5.2