2011-11-23 36 views
2

我在數據表中使用延遲加載和分頁,並且正常工作。問題是我在同一個html頁面中有一個高級搜索功能,當我點擊搜索按鈕時,我希望我的dataTable根據我在高級搜索字段中輸入的值進行更新(此功能在DaoFactory.getDocumentoDao().buscarLazy(first, pageSize) , 代碼如下,但我的按鈕的更新屬性似乎沒有做任何事情,因爲懶惰模型的加載方法沒有被調用,所以問題是:我可以以某種方式調用懶惰模型的加載方法該模型以外面有我的dataTable更新從另一個組件更新數據表(使用延遲加載)

FORM:

<h:form id="frmCli"> 
    <p:commandButton value="Buscar" 
        update="frmCli:panelResultadosDoc"/> 
    <h:panelGroup id="panelResultadosDoc"> 
     <div class="dataTable">  
      <p:dataTable id="documentos" 
         value="#{documentoBuscadorBean.lazyModel}" 
         lazy="true" 
         var="varDocBean" 
         paginator="true" 
         paginatorPosition="bottom" 
         paginatorAlwaysVisible="false" 
         rows="5">   
       <p:column> 
        <f:facet name="header">Código</f:facet> 
        <h:outputText value="#{varDocBean.documento.id}"/> 
       </p:column>               
      </p:dataTable> 
     </div>  
    </h:panelGroup> 
</h:form> 

BEAN包含模型:

@ManagedBean 
@SessionScoped 
public class DocumentoBuscadorBean { 

    private LazyDataModel<DocumentoBean> lazyModel; 

    @SuppressWarnings("serial") 
    public DocumentoBuscadorBean() { 

     lazyModel = new LazyDataModel<DocumentoBean>() { 

     public List<DocumentoBean> load(int first, int pageSize, String sortField, boolean sortOrder, Map<String,String> filters) { 
      List<DocumentoBean> lazyListDocumentos = new ArrayList<DocumentoBean>(); 
       try {     
        lazyListDocumentos = DaoFactory.getDocumentoDao().buscarLazy(first, pageSize); 
      } catch (DocumentoException e) { 
       e.printStackTrace(); 
      } 
       return lazyListDocumentos; 
      }   
     };    
     lazyModel.setRowCount(DaoFactory.getDocumentoDao().rowCount()); 
     lazyModel.setPageSize(5); 
    } 
    public LazyDataModel<DocumentoBean> getLazyModel() { 
     return lazyModel; 
    } 

} 

回答

2

如果我不是失去了一些東西,你可以只用行動:

<p:commandButton value="Buscar" 
       action="#{documentoBuscadorBean.lazyModel.load(0,10,...)}" 
       process="@form" 
       update="frmCli:panelResultadosDoc"/> 

這將是更好的負載添加的參數的版本,這樣你就不會在您的視圖混合邏輯。如果因爲某些原因不能使用EL 2.2,這甚至是必需的(儘管我強烈建議使用EL 2.2,爲您節省了很多醜陋的f:param處理)。

+0

在JSF中不能添加這樣的PARAM值! – spauny

+0

@spauny請閱讀例如http://stackoverflow.com/questions/3599948/jsf2-action-parameter並刪除這種誤導downvote。如果OP使用JSF 1,則很容易創建無參數的加載版本。 – mrembisz

+0

這取決於EL實現。只有JBoss EL和JSP 2.2 EL才能做到這一點...同樣使用Seam可以實現這一點...使用簡單的JSF + Primefaces,這不是可能的。投票不能被刪除,除非你編輯你的文章,並張貼另一種方式添加參數... – spauny

0

這是什麼意思#{varDocBean.documento.id}varDocBeanDocumentoBean - so documento是DocumentoBean的屬性?

此外,什麼commandButton不會做任何事情?我只看到一個commandButton,但是沒有操作方法。

你應該在Primefaces實驗室展示了lazy dataTable(再次)一起來看看:http://www.primefaces.org/showcase-labs/ui/datatableLazy.jsf