2016-05-14 75 views
1

我最近下載了這個由Simtay應用SimpleCRUD。我在Netbeans 8.0.1上加載了該項目並添加了必要的庫。我得到這個錯誤:錯誤解析文件:LazyUserDataModel.java上Simtay SimpleCRUD

@Override public List load(int first, int pageSize, String sortField, SortOrder sortOrder, Map filters) on the class

LazyUserDataModel.java

下面是這個類。

package com.nz.simplecrud.controller; 


import com.nz.simplecrud.entity.User; 
import com.nz.simplecrud.service.DataAccessService; 
import com.nz.simplecrud.util.LazySorter; 
import java.io.Serializable; 
import java.util.Collections; 
import java.util.List; 
import java.util.Map; 
import org.primefaces.model.LazyDataModel; 
import org.primefaces.model.SortOrder; 

/** 
* 
* Custom Lazy User DataModel which extends PrimeFaces LazyDataModel. 
* For more information please visit http://www.primefaces.org/showcase-labs/ui/datatableLazy.jsf 
*/ 

public class LazyUserDataModel extends LazyDataModel<User> implements Serializable{ 

    // Data Source for binding data to the DataTable 
    private List<User> datasource; 
    // Selected Page size in the DataTable 
    private int pageSize; 
    // Current row index number 
    private int rowIndex; 
    // Total row number 
    private int rowCount; 
    // Data Access Service for create read update delete operations 
    private DataAccessService crudService; 

    /** 
    * 
    * @param crudService 
    */ 
    public LazyUserDataModel(DataAccessService crudService) { 
     this.crudService = crudService; 
    } 

    /** 
    * Lazy loading user list with sorting ability 
    * @param first 
    * @param pageSize 
    * @param sortField 
    * @param sortOrder 
    * @param filters 
    * @return List<User> 
    */ 
    @Override 
    public List<User> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) { 
     datasource = crudService.findWithNamedQuery(User.ALL, first, first + pageSize); 
     // if sort field is not null then we sort the field according to sortfield and sortOrder parameter 
     if(sortField != null) { 
      Collections.sort(datasource, new LazySorter(sortField, sortOrder)); 
     } 
     setRowCount(crudService.countTotalRecord(User.TOTAL)); 
     return datasource; 
    } 

    /** 
    * Checks if the row is available 
    * @return boolean 
    */ 
    @Override 
    public boolean isRowAvailable() { 
     if(datasource == null) 
      return false; 
     int index = rowIndex % pageSize ; 
     return index >= 0 && index < datasource.size(); 
    } 

    /** 
    * Gets the user object's primary key 
    * @param user 
    * @return Object 
    */ 
    @Override 
    public Object getRowKey(User user) { 
     return user.getId().toString(); 
    } 

    /** 
    * Returns the user object at the specified position in datasource. 
    * @return 
    */ 
    @Override 
    public User getRowData() { 
     if(datasource == null) 
      return null; 
     int index = rowIndex % pageSize; 
     if(index > datasource.size()){ 
      return null; 
     } 
     return datasource.get(index); 
    } 

    /** 
    * Returns the user object that has the row key. 
    * @param rowKey 
    * @return 
    */ 
    @Override 
    public User getRowData(String rowKey) { 
     if(datasource == null) 
      return null; 
     for(User user : datasource) { 
      if(user.getId().toString().equals(rowKey)) 
      return user; 
     } 
     return null; 
    } 


    /* 
    * ===== Getters and Setters of LazyUserDataModel fields 
    */ 


    /** 
    * 
    * @param pageSize 
    */ 
    @Override 
    public void setPageSize(int pageSize) { 
     this.pageSize = pageSize; 
    } 

    /** 
    * Returns page size 
    * @return int 
    */ 
    @Override 
    public int getPageSize() { 
     return pageSize; 
    } 

    /** 
    * Returns current row index 
    * @return int 
    */ 
    @Override 
    public int getRowIndex() { 
     return this.rowIndex; 
    } 

    /** 
    * Sets row index 
    * @param rowIndex 
    */ 
    @Override 
    public void setRowIndex(int rowIndex) { 
     this.rowIndex = rowIndex; 
    } 

    /** 
    * Sets row count 
    * @param rowCount 
    */ 
    @Override 
    public void setRowCount(int rowCount) { 
     this.rowCount = rowCount; 
    } 

    /** 
    * Returns row count 
    * @return int 
    */ 
    @Override 
    public int getRowCount() { 
     return this.rowCount; 
    } 

    /** 
    * Sets wrapped data 
    * @param list 
    */ 
    @Override 
    public void setWrappedData(Object list) { 
     this.datasource = (List<User>) list; 
    } 

    /** 
    * Returns wrapped data 
    * @return 
    */ 
    @Override 
    public Object getWrappedData() { 
     return datasource; 
    } 
} 

請幫忙嗎?

+0

您正在使用哪個版本的Primefaces? – Unknown

+0

你想添加方法公共列表加載(int第一,int pageSize,字符串sortField,SortOrder sortOrder,地圖過濾器)到您的類? – Unknown

+0

@未知我正在運行pf 5.我實際上正在嘗試運行該項目。我還沒有添加任何方法 – bademba

回答

1

規則重寫

The argument list should be exactly the same as that of the overridden method. The return type should be the same or a subtype of the return type declared in the original overridden method in the super class.

LazyDataModel類有稱爲負載的方法(Primefaces 5)

public List<T> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) { 
throw new UnsupportedOperationException("Lazy loading is not implemented."); 
} 

如果您正在使用Primefaces 5.

只能替換在LazyUserDataModel上述方法

由於方法

load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) 

不存在於LazyDataModel(PF5)中,有錯誤是正常的。

那麼如何解決?

變化Map<String,String> filtersMap<String, Object> filters(爲了覆蓋需要有相同的簽名)

注:Simtay項目是使用PF3.4寫着字,用LazyDataModel

+0

我會嘗試實施你的想法,我希望它會解決我的頭痛 – bademba

+0

沒有喧囂的哥們。我會在傍晚 – bademba

+0

嘗試,它的工作就像一個魔術。 a +爲你 – bademba