2013-10-16 32 views
-1

我構建了一個相對簡單的數據表,並嘗試使用過濾器功能並使用分頁功能。Primefaces 4.0 - 分頁數據表過濾問題

參照primefaces showcase我爲我的Customer類中的每個字段創建了一列。

這是我的「控制器」豆:

@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隨每次擊鍵都發生變化。

+0

我不明白它是如何顯示過濾的數據,即使刷新頁面後。 'filterBy'屬性必須接收客戶的字段'name'。請參閱primefaces用戶指南的第135頁。希望它有幫助^^ – Cold

+0

是的我的朋友@ Vogel612。 – Cold

+0

什麼是你的primefaces版本? – Cold

回答

1

你的filterBy和sortBy必須包含一個延遲的EL表達式。

<p:Column id="nameColumn" filterBy="#{customer.name}" sortBy="#{customer.name}" 
    headerText="Customer" filterMatchMode="contains"> 
    <h:outputText value="#{customer.name}" /> 
</p:Column> 

UPDATE: 因爲我可以證實,EL和非EL的做法都工作在PF V4.0,這裏是另一個可能的回答您的問題:

請檢查您的SessionScoped進口。

我無法使用javax.faces.bean.SessionScoped工作。 使用javax.enterprise.context.SessionScoped它工作。

就我個人而言,我儘量避免使用SessionScoped作用域,請嘗試使用ConversationScoped來代替。它會更好地使用您的服務器資源。

+0

你是以什麼爲基礎的?如果我可以引用v 4.0的用戶指南: 「定義* sortBy *屬性可在該特定列上啓用基於AJAX的排序。[...] sortBy =」model「headerText =」Model「」(參見第140頁)可以在第142頁找到filterBy的句子和示例。 – Vogel612

+0

我只是看着我的代碼。但我使用的版本是3.4.2。我會檢查4.0。 – Yamada

+0

我剛剛將我的項目中的PF更新到4.0,並且它可以無縫地工作......您可以嘗試這種方法並查看它是否有效? – Yamada

0

public CustomerListController(){ 
    //some Class that generates a list of sufficiently many 
    //dummy customers on instantiation 
    this.allCustomers = new CustomerListProducer().getCustomers(); 
    this.setFilteredCustomers(this.getAllCustomers()); 
} 

沒有價值是提供給filterAttribute因此,你看到一個空白dataTable的,當你做過濾器更換你的代碼。

希望這個幫助的

+0

抱歉,但這也沒有奏效。過濾器仍然只是返回空表,並且即使在清除過濾字段後,該表仍然爲空。 – Vogel612

+0

您是否將您的課程設置爲@ManagedBean(「某個名稱」) – BholaVishwakarma

+0

您是否在控制檯 – BholaVishwakarma