比較的単純なDataTableを作成し、ページネーション機能も使用してフィルター機能を使用しようとしました。
Primefacesのショーケースを参照して、Customer
クラスの各フィールドに列を作成しました。
これは私の「コントローラー」Beanです。
@SessionScoped
@Named
public class CustomerListController implements Serializable{
public static final long serialVersionUID = //UID;
private List<Customer> filteredCustomers;
private List<Customer> allCustomers;
public CustomerListController(){
//some Class that generates a list of sufficiently many
//dummy customers on instantiation
this.allCustomers = new CustomerListProducer().getCustomers();
}
public List<Customer> getFilteredCustomers{
return this.filteredCustomers;
}
public void setFilteredCustomers(List<Customers> list){
this.filteredCustomers = list;
}
public List<Customer> getAllCustomers(){
return this.allCustomers;
}
}
私はこれをレンダリングするために次のdataTableを使用します:
<p:dataTable paginator="true" rows="18" scrollRows="15" scrollable="true"
scrollHeight="500" var="customer" value="#{customerListController.allCustomers}"
scrollable="true" id="customerTable"
filteredValue="#{customerListController.filteredCustomers}" widgetVar="table">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search all fields:" />
<h:inputText id="globalFilter" onkeyup="table.filter()" />
</p:outputPanel>
</f:facet>
<p:Column id="nameColumn" filterBy="name" sortBy="name"
headerText="Customer" filterMatchMode="contains">
<h:outputText value="#{customer.name}" />
</p:Column>
<!-- Some more columns in the exactly same
manner as this changes only in Customer attribute-->
</p:dataTable>
特定のフィルターフィールドで任意のキーを押すと、テーブルはすべての行を失い、フィールドをクリアしても何も表示されません。
ページを更新すると、予想される行数とページ数が表示されます。
要請に応じて修正を提供するよう努めます。
編集:
MavenとともにインストールされたPrimefacesバージョン4.0.0を使用しています。
FFの下のコンソールを調べていて、次のことがわかりました
。応答XMLが空で、更新されたテーブルのノードエントリを保存します。JavaScriptエラーはスローされず、「テーブルデータ」とともに送信されるビューステートIDはキーストロークごとに変化します。
filterByとsortByには、遅延EL式が含まれている必要があります。
<p:Column id="nameColumn" filterBy="#{customer.name}" sortBy="#{customer.name}"
headerText="Customer" filterMatchMode="contains">
<h:outputText value="#{customer.name}" />
</p:Column>
更新: ELアプローチと非ELアプローチの両方がPF V4.0で機能することを確認できたので、ここにあなたの問題に対する別の可能な答えがあります:
SessionScopedのインポートを確認してください。
javax.faces.bean.SessionScopedを使用して動作させることができませんでした。javax.enterprise.context.SessionScopedを使用すると、機能しました。
個人的には、SessionScopedスコープの使用をできるだけ避け、代わりにConversationScopedを使用してみてください。それはあなたのサーバーリソースのより良い使用法になります。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加