2016-04-28 71 views
0

想要過濾通過數據表顯示的查詢的結果集。行選擇,點擊列標題的行排序和數據表的分頁功能正常工作。當我加入primefaces過濾functionnality到DataTable,然後我碰上DataModel必須使用primefaces過濾器實現org.primefaces.model.SelectableDataModel異常過濾器

javax.faces.FacesException:啓用選擇時的DataModel必須實現 org.primefaces.model.SelectableDataModel。

對象實體:

@Entity 
@Table(name="Customer", 
     uniqueConstraints={@UniqueConstraint(columnNames={"ID"})}) 

public class Customer { 
    @Id 
    @GeneratedValue(strategy=GenerationType.IDENTITY) 
    @Column(name="ID", nullable=false, unique=true, length=11) 
    private Integer id; 

    @Column(name="LASTNAME", length=40, nullable=false) 
    private String lastName; 

    @Column(name="FIRSTNAME", length=30, nullable=true) 
    private String firstName; 
.... 
} 

託管Bean:

@ManagedBean(name = "customerController") 
@ViewScoped 

public class CustomerController implements Serializable { 

    private static final long serialVersionUID = 1L; 
    private Customer selectedCustomer = new Customer(); 
    private List<Customer> customers = new ArrayList<Customer>(); 
    private String message; 

    public CustomerController() { 
    } 

    @PostConstruct 
    void init() {   
     CustomerDAO custDAO = new CustomerDAO(); 
     customers = custDAO.getAllCustomers(); 

     // select first row 
     if (customers != null) selectedCustomer=customers.get(0); 
    } 

    public void onRowSelect(SelectEvent event) { 
     message = ""; 
    } 

    public void onRowUnselect(UnselectEvent event) { 
     message = ""; 
    } 

    // getters and setters 
    ... 
} 

的facelet:

<ui:define name="contentPart1" >    
    <h:form id="contentPart1Form"> 
     <p:dataTable id="singleSelection" var="customer" value="#{customerController.customers}" rowKey="#{customer.id}" 
      selection="#{customerController.selectedCustomer}" selectionMode="single" paginator="true" rows="10"> 
      <p:ajax event="rowSelect" listener="#{customerController.onRowSelect}" /> 

      <p:column headerText="#{msg['customerCRUD.labelIdentifier']}" style="width:15%;"> 
       <h:outputText value="#{customer.id}" readonly="#{facesContext.currentPhaseId.ordinal eq 6}"/> 
      </p:column> 
      <p:column headerText="#{msg['customerCRUD.labelFirstName']}" sortBy="#{customer.firstName}" style="width:30%;"> 
       <h:outputText value="#{customer.firstName}" /> 
      </p:column> 
      <p:column headerText="#{msg['customerCRUD.labelLastName']}" filterBy="#{customer.lastName}" filterMatchMode="contains" 
       sortBy="#{customer.lastName}"> 
       <h:outputText value="#{customer.lastName}" /> 
      </p:column> 

      <f:facet name="footer"> 
       <h:outputText value=" "/> 
      </f:facet>     
     </p:dataTable>    
    </h:form> 
</ui:define> 

回答

1

經過調查的時間,我終於實現上,我是賓語實體appliyng過濾器是不可序列化的。 該解決方案是從序列化類繼承對象實體。

@Entity 
@Table(name="Customer", 
     uniqueConstraints={@UniqueConstraint(columnNames={"ID"})}) 

public class Customer implements Serializable{ 

/** 
* 
*/ 
private static final long serialVersionUID = 1L;{ 
    @Id 
    @GeneratedValue(strategy=GenerationType.IDENTITY) 
    @Column(name="ID", nullable=false, unique=true, length=11) 
    private Integer id; 

    @Column(name="LASTNAME", length=40, nullable=false) 
    private String lastName; 

    @Column(name="FIRSTNAME", length=30, nullable=true) 
    private String firstName; 
.... 
} 
+1

可序列化是一個接口,所以你不會繼承但實現 –

相關問題