我在本教程http://uaihebert.com/?p=1120之后实现了lazyDataModel
我的代码与本教程有点不同,这里是:
看法:
<p:dataTable id="tablaClientes" value="#{AgendaManualMBean.allClientes}"
var="tablaClientes"
widgetVar="clienteTable"
rowKey="#{tablaClientes.clDocid}"
selection="#{AgendaManualMBean.ciatt001}" selectionMode="single" rows="10"
lazy="true" paginatorPosition="top"
paginatorTemplate="{RowsPerPageDropdown}{FirstPageLink}{PreviousPageLink}
{CurrentPageReport} {NextPageLink} {LastPageLink}" rowsPerPageTemplate="5,10,15"
emptyMessage="No existen clientes">
<f:facet name="header" >
<p:outputPanel>
<h:outputText value="Busqueda " />
<p:inputText id="globalFilter" onkeyup="clienteTable.filter()"
style="width:150px" size="10"/>
</p:outputPanel>
</f:facet>
<p:column id="numOrdenColumn" filterBy="#{tablaClientes.clDocid}"
width="50"
headerText="Identificación"
filterMatchMode="contains">
<h:outputText value="#{tablaClientes.clDocid}" />
</p:column>
<p:column id="nomCliColumn"
filterBy="#{tablaClientes.clNombre1}"
width="250"
headerText="Cliente"
filterMatchMode="contains">
<h:outputText value="#{tablaClientes.clNombre1}" />
</p:column>
</p:dataTable>
我的托管豆:
public LazyDataModel<Ciatt001> getAllClientes() {
if (listaClientesLazy == null) {
listaClientesLazy = new LazyClienteModel(ambiente.getCodCia(),ambiente.getCodAge());
//listaClientesLazy = new LazyClienteModelMBean();
}
return listaClientesLazy;
}
我的懒惰数据模型
public List<Ciatt001> load(int startingAt, int maxPerPage, String sortField, SortOrder sortOrder, Map<String, String> filters) {
String a = "";
try {
listaClientes = new ArrayList<Ciatt001>();
a = String.valueOf(agendamientoSession.countClientes2(cia, age));
listaClientes = agendamientoSession.listaClientes2(cia, age, startingAt, maxPerPage);
} catch (Exception e) {
e.printStackTrace();
}
if (getRowCount() <= 0) {
setRowCount(Integer.parseInt(a));
}
setPageSize(maxPerPage);
return listaClientes;
}
@Override
public Object getRowKey(Ciatt001 ciatt001) {
return ciatt001.getClDocid();
}
@Override
public Ciatt001 getRowData(String docid) {
//Integer id = Integer.valueOf(idBandeja);
for (Ciatt001 ciatt001 : listaClientes) {
if (docid.equals(ciatt001.getClDocid())) {
return ciatt001;
}
}
return null;
}
和 ejb 方法:
public List<Ciatt001> listaClientes2(String cia, String age ,int startingAt, int maxPerPage) {
Query query = em.createNamedQuery("Ciatt001.listaClientesPorCiaPorAge2");
query.setParameter(1, cia);
query.setParameter(2, age);
query.setFirstResult(startingAt);
query.setMaxResults(maxPerPage);
return query.getResultList();
}
public String countClientes2(String cia, String age) {
Query query = em.createNamedQuery("Ciatt001.countClientes2");
query.setParameter(1, cia);
query.setParameter(2, age);
return query.getSingleResult().toString();
}
如何使用此延迟加载实现实现全局过滤器?