Tabela
<h:form id="form2" prependId="false">
<p:dataTable id="tabela" var="movimento" value="#{movimentoBean.lazyModel}"
paginator="true" rows="10" paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink}
{PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15" selectionMode="single" selection="#{movimentoBean.movimento}"
rowKey="#{movimento.codMovimento}" rowSelectListener="#{movimentoBean.rowSelected}"
emptyMessage="Nenhum registro foi encontrado." width="100%" rendered="#{not empty movimentoBean.movimentos}"
lazy="true" update="tabela">
<f:facet name="header">
</f:facet>
<p:ajax event="rowSelect" listener="#{movimentoBean.onRowSelect}"
oncomplete="PF('movDialog').show()"/> <!-- update=":form2:display"-->
<p:column filterBy="#{movimento.contrato.numContrato}"
headerText="Contrato" filterMatchMode="contains">
<h:outputText value="#{movimento.contrato.numContrato}"></h:outputText>
</p:column>
<p:column headerText="Fornecedor" filterMatchMode="contains">
<h:outputText
value="#{movimento.contrato.fornecedor.nomeFornecedor}"></h:outputText>
</p:column>
<p:column headerText="Serviço" filterMatchMode="contains">
<h:outputLabel value="#{movimento.contrato.servicos}"></h:outputLabel>
</p:column>
<p:column headerText="Localidade" filterMatchMode="contains">
<h:outputText value="#{movimento.localidade.nomeLocalidade}"></h:outputText>
</p:column>
<p:column headerText="Valor" filterMatchMode="contains">
<h:outputText value="#{movimento.valor}">
<f:convertNumber currencyCode="BRL" type="currency" />
</h:outputText>
</p:column>
<p:column filterBy="#{movimento.anoMes}" headerText="Data"
filterMatchMode="contains">
<h:outputText value="#{movimento.anoMes}">
<f:convertDateTime pattern="yyyy/MM" />
</h:outputText>
</p:column>
</p:dataTable>
<p:dialog header="Movimento Detalhe" widgetVar="movDialog"
resizable="false" showEffect="explode" hideEffect="explode"
appendToBody="true">
<h:panelGrid id="display" columns="2" cellpadding="4">
<f:facet name="header">
<!-- <p:graphicImage value="/images/cars/#{tableBean.selectedCar.manufacturer}.jpg"/> -->
</f:facet>
<h:outputText value="Contrato:" />
<h:outputText
value="#{movimentoBean.movimentoSelecionado.contrato}"
style="font-weight:bold" />
<h:outputText value="Fornecedor:" />
<h:outputText
value="#{movimentoBean.movimentoSelecionado.contrato.fornecedor}"
style="font-weight:bold" />
<h:outputText value="Serviços:" />
<h:outputText
value="#{movimentoBean.movimentoSelecionado.contrato.servicos}"
style="font-weight:bold" />
<h:outputText value="Localidade:" />
<h:outputText
value="#{movimentoBean.movimentoSelecionado.localidade}"
style="font-weight:bold" />
<h:outputText value="Valor:" />
<h:outputText value="#{movimentoBean.movimentoSelecionado.valor}"
style="font-weight:bold" />
<h:outputText value="Data:" />
<h:outputText value="#{movimentoBean.movimentoSelecionado.anoMes}"
style="font-weight:bold" />
</h:panelGrid>
</p:dialog>
</h:form>
ManagedBean
public class MovimentoBean extends BaseBean implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private Movimento movimento = new Movimento();
private List<Movimento> movimentos;
private Movimento movimentoSelecionado;
private LazyDataModel<Movimento> lazyModel;
public MovimentoBean() {
lazyModel = new LazyMovimentoDataModel(this.getMovimentos());
}
public Movimento getMovimento() {
return movimento;
}
public void setMovimento(Movimento movimento) {
this.movimento = movimento;
}
public Integer getContratoID() {
return contratoID;
}
public void setContratoID(Integer contratoID) {
this.contratoID = contratoID;
}
public Integer getLocalidadeID() {
return localidadeID;
}
public void setLocalidadeID(Integer localidadeID) {
this.localidadeID = localidadeID;
}
public Integer getMovimentoID() {
return movimentoID;
}
public void setMovimentoID(Integer movimentoID) {
this.movimentoID = movimentoID;
}
public void setMovimentos(List<Movimento> movimentos) {
this.movimentos = movimentos;
}
public List<Movimento> getMovimentos() {
EntityManager manager = this.getManager();
MovimentoIRepositorio<Movimento> repositorio = new MovimentoRepositorio(
manager);
try {
this.movimentos = repositorio.getLista();
} catch (RepositorioException e) {
this.addErrorMessage(e.getMessage());
}
return this.movimentos;
}
public Movimento getMovimentoSelecionado() {
return movimentoSelecionado;
}
public void setMovimentoSelecionado(Movimento movimentoSelecionado) {
this.movimentoSelecionado = movimentoSelecionado;
}
public void setMovimentoSelecionado(Movimento movimentoSelecionado, SelectEvent event) {
movimentoSelecionado = (Movimento) event.getObject();
this.movimentoSelecionado = movimentoSelecionado;
}
public LazyDataModel<Movimento> getLazyModel() {
return lazyModel;
}
public void setLazyModel(LazyDataModel<Movimento> lazyModel) {
this.lazyModel = lazyModel;
}
public void limparPesquisa(CloseEvent closeEvent) {
movimentos.clear();
}
public void rowSelected(SelectEvent selectEvent) {
if (selectEvent.getObject() != null) {
setMovimento((Movimento) selectEvent.getObject());
}
}
public String nextStep(FlowEvent flowEvent) {
if (flowEvent.getNewStep().equals("undefined")) {
return "movimentoTab";
} else if (movimento == null) {
this.addErrorMessage("Escolha um movimento.");
return flowEvent.getOldStep();
} else {
return flowEvent.getNewStep();
}
}
public void onRowSelect(SelectEvent event) {
FacesMessage msg = new FacesMessage("Movimento Selecionado",
((Movimento) event.getObject()).getContrato().getNumContrato());
movimentoSelecionado = (Movimento) event.getObject();
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onRowUnselect(UnselectEvent event) {
FacesMessage msg = new FacesMessage("Movimento Não Selecionado", ((Movimento) event.getObject()).getContrato().getNumContrato());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
private EntityManager getManager() {
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
HttpServletRequest request = (HttpServletRequest) ec.getRequest();
return (EntityManager) request.getAttribute("EntityManager");
}
}
LazyDataModel
public class LazyMovimentoDataModel extends LazyDataModel<Movimento>{
/**
*
*/
private static final long serialVersionUID = 1L;
private List<Movimento> datasource;
public LazyMovimentoDataModel(List<Movimento> datasource) {
this.datasource = datasource;
}
@Override
public Movimento getRowData(String rowKey) {
for(Movimento movimento : datasource) {
if(movimento.getContrato().getNumContrato().equals(rowKey))
return movimento;
}
return null;
}
@Override
public Object getRowKey(Movimento movimento) {
return movimento.getContrato().getNumContrato();
}
@Override
public List<Movimento> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {
List<Movimento> data = new ArrayList<Movimento>();
//filter
for(Movimento movimento : datasource) {
boolean match = true;
for(Iterator<String> it = filters.keySet().iterator(); it.hasNext();) {
try {
String filterProperty = it.next();
String filterValue = filters.get(filterProperty);
String fieldValue = String.valueOf(movimento.getClass().getField(filterProperty).get(movimento));
if(filterValue == null || fieldValue.startsWith(filterValue)) {
match = true;
}
else {
match = false;
break;
}
} catch(Exception e) {
match = false;
}
}
if(match) {
data.add(movimento);
}
}
//sort
/*
if(sortField != null) {
Collections.sort(data, new LazySorter(sortField, sortOrder));
}
*/
//rowCount
int dataSize = data.size();
this.setRowCount(dataSize);
//paginate
if(dataSize > pageSize) {
try {
return data.subList(first, first + pageSize);
}
catch(IndexOutOfBoundsException e) {
return data.subList(first, first + (dataSize % pageSize));
}
}
else {
return data;
}
}
}
Alguém pode ajudar?