我在數據表中使用延遲加載和分頁,並且正常工作。問題是我在同一個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;
}
}
在JSF中不能添加這樣的PARAM值! – spauny
@spauny請閱讀例如http://stackoverflow.com/questions/3599948/jsf2-action-parameter並刪除這種誤導downvote。如果OP使用JSF 1,則很容易創建無參數的加載版本。 – mrembisz
這取決於EL實現。只有JBoss EL和JSP 2.2 EL才能做到這一點...同樣使用Seam可以實現這一點...使用簡單的JSF + Primefaces,這不是可能的。投票不能被刪除,除非你編輯你的文章,並張貼另一種方式添加參數... – spauny