同じモデルとコントローラを使用する3つのテストWebアプリケーションがありますが、違いはJSFセッション管理Beanにあります。PrimeFaces DataTable JSFデータモデルではソートとフィルタリングが機能しません
アプリケーションアイテムを取得するためにとC使用JSFのDataModel: JPAクエリの結果セットが、その後ListDataModelに包まれているJavaのリストを返します。この後者の値は、PrimeFaces dataTableで表示される項目です。 A JPAクエリ結果セットはPrimeFaces 2.2.1のdataTableによって表示された項目の値であるJavaのリストを返す:
アプリケーションBは、アイテムを取得するためのJava LISTを使用します。
アプリケーションBでのソートとフィルタリングは完全に機能し、高速ですが、アプリケーションAとCでは致命的ではありません。
Richfaces、OpenFacesなどの他のライブラリの並べ替えでのフィルタリングは、この同じコードを使用してそのまま使用できます。
問題はPrimeFaces 3.0.0にも残ります。これはバグですか?
コード:アプリAで
private List<Customer> items = null;
// remainder of code here
public List<Customer> getCustomerItems() {
if (customerItems == null) {
getPagingInfo();
customerItems = jpaController.findCustomerEntities(pagingInfo.getBatchSize(), pagingInfo.getFirstItem());
}
return customerItems;
}
:
コード:
private DataModel items = null;
public PaginationHelper getPagination() {
if (pagination == null) {
pagination = new PaginationHelper(999999) {
@Override
public int getItemsCount() {
return getJpaController().getChimioCount();
}
@Override // The list of Customers is wrapped in a JSF ListDataModel
public DataModel createPageDataModel() {
return new ListDataModel(getJpaController().findCustomerEntities(getPageSize(), getPageFirstItem()));
}
};
}
return pagination;
}
/**
* this goes for the value attribute in a datatable to list all the Customer items
*/
public DataModel getItems() {
if (items == null) {
items = getPagination().createPageDataModel();
}
return items;
}
アプリBで
- アプリケーションCで3210
:
コード:
private DataModel<Project> items; // remainder of code here /** *The ListDataModel is initialized here */ public void init() { try { setProjectList(doInTransaction(new PersistenceAction<List<Project>>() { public List<Project> execute(EntityManager em) { Query query = em.createNamedQuery("project.getAll"); return (List<Project>) query.getResultList(); } })); } catch (ManagerException ex) { Logger.getLogger(ProjectManager.class.getName()).log(Level.SEVERE, null, ex); } projectItems = new LinkedList<SelectItem>(); projectItems.add(new SelectItem(new Project(), "-- Select one project --")); if (getProjectList() != null) { projects = new ListDataModel<Project>(getProjectList()); for (Project p : getProjectList()) { projectItems.add(new SelectItem(p, p.getName())); } } }
はあなたの助けのために事前にありがとうございます。
フォーラムで同じ回答がありました。実際にListDataModelのソートは最後のスナップショット3.0M2で修正されました。また、フィルタリング用のチケットを作成しています。感謝のジム – Hanynowsky
最新のスナップショットについてのヘッドアップありがとう。私はまだListDataModelを使用していませんが、将来私はそれを必要とするでしょう。 –