2013-06-03 65 views
4

我得到「java.lang.UnsupportedOperationException:延遲加載未執行。」錯誤。當我degub項目,lazyModel的構造函數工作,但加載方法不執行。primefaces延遲加載未執行

my xhtml page;

<p:dataTable id="envelopelistid" var="envelope" 
        value="#{incomingEnvelopeListController.lazyEnvelopeDataModel}" 
        selection="#{incomingEnvelopeListController.selectedEnvelope}" selectionMode="single" 
        rowKey="#{envelope.instanceIdentifier}" 
        sortMode="multiple" 
        lazy="true" 
        style="min-height: 300px" 
        paginator="true" 
        paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}" 
        rowsPerPageTemplate="5,10,15" 
        rows="10"> 

我的控制器;

private LazyDataModel<Envelope> lazyEnvelopeDataModel; 

public void init(){ 
... 
lazyEnvelopeDataModel = new LazyEnvelopeDataModel(genericService,envelope); 
} 

我的懶數據模型;

@Override 
public List<Envelope> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) { 

    if (sortField == null) { 
     sortField = "identificationId"; 
    } 

    datasource = genericService.getByTemplate(envelopeModel, first, pageSize, new Order(sortField, Order.convertSortOrder(sortOrder.toString()))); 
    setRowCount((int) genericService.getCountByTemplate(envelopeModel)); 
    return datasource; 


} 

回答

14

有2種load方法LazyDataModel

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

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

這就是引發錯誤。你正在使用multisort,所以你應該重寫第二個。

+2

我剛碰到同樣的問題。這些方法不應該抽象嗎? – Stefan

+0

我同意。如果沒有提供默認實現,請讓它們抽象以便開發人員知道它們必須自己提供實現。 – divinedragon