Loading Lazy in Datatable of Primefaces does not bring the record data

Asked

Viewed 204 times

2

I got a shipment lazy in DataTable of Primefaces, and in this table I upload I want to edit a record.

Clicking on the line will open a dialog with a form for editing that record. But clicking on the line opens the dialog but does not load log data for editing.

This is the bean:

private LazyDataModel<LancamentoTributoCdg> model;

public PagamentoTributoCdgBean() {
    this.limpar();
    this.limparBaixa();

    // Busca
    filtro = new MovimentoPagarLancamentoFilterCdg();
    lancamentosFiltrados = new ArrayList<>();

    model = new LazyDataModel<LancamentoTributoCdg>() {
        private static final long serialVersionUID = 1L;

        @Override
        public List<LancamentoTributoCdg> load(int first, int pageSize, String sortField, SortOrder sortOrder,
                Map<String, Object> filters) {
            filtro.setPrimeiroRegistro(first);
            filtro.setQuantidadeRegistros(pageSize);
            filtro.setPropriedadeOrdenacao(sortField);
            filtro.setAscendente(SortOrder.ASCENDING.equals(sortOrder));

            setRowCount(lancamentosTributos.quantidadeFiltrados(filtro));
            return lancamentosTributos.filtrados(filtro);
        }

        @Override
        public LancamentoTributoCdg getRowData(String rowKey) {
            if (rowKey != null) {
                for (LancamentoTributoCdg lancamento : lancamentosTributos.filtrados(filtro)) {
                    if (lancamento.getId().equals(rowKey))
                        lancamentoSelecionnado=lancamento;
                        return lancamentoSelecionnado;
                }
            }
            return null;
        }

    };

}

// Datable (seleciona a linha e chama o metodo)
public void onRowSelect(SelectEvent event) {
    lancamento = (LancamentoTributoCdg) event.getObject();
    listaBancos = bancos.bancoRepository(StatusConta.ATIVA);
}

And this is HTML:

<p:dataTable id="lancamentoTable" lazy="true"
    value="#{pagamentoTributoCdgBean.model}"
    widgetVar="lancamentoTableWidgetVar"
    var="lancamento" scrollable="true" scrollHeight="460"
    style="margin-top: 2px;" emptyMessage="Nenhum lançamento." rows="10"
    paginator="true" 
    rowsPerPageTemplate="10,12,15,20" paginatorPosition="bottom"
    selectionMode="single"
    selection="#{pagamentoTributoCdgBean.lancamentoSelecionnado}"
    rowKey="#{lancamento.id}">

    <p:ajax event="rowSelect" disabled="#{not seguranca.administrador}"
        listener="#{pagamentoTributoCdgBean.onRowSelect}"
        oncomplete="PF('inserirBancoVar').show();" process="@this"
        update=":incluirBanco:inclusaoPanelGroup :incluirBanco:botaoConfirmar :incluirBanco:botaoTrocarBanco :incluirBanco:botaoSalvar :incluirBanco:botaoAtivaNota :incluirBanco:botaoCancelarNota" />

    <p:column headerText="NUMERO" style="width: 60px">
        <h:outputText value="#{lancamento.numeroNota}"
            style="float: right; #{lancamento.cancelada ? 'color: red' : ''}" />
    </p:column>

Presents this error when the dialog is loaded:

GRAVE: Could not handle exception!
java.lang.IllegalStateException: Cannot call reset() after response has been committed

1 answer

0

It’s all sorted out. I did so `private Lazydatamodel model model;

public PagamentoTributoCdgBean() {
    this.limpar();
    this.limparBaixa();
    // Busca
    filtro = new MovimentoPagarLancamentoFilterCdg();

    model = new LazyDataModel<LancamentoTributoCdg>() {
        private static final long serialVersionUID = 1L;

        @Override
        public List<LancamentoTributoCdg> load(int first, int pageSize, String sortField, SortOrder sortOrder,
                Map<String, Object> filters) {
            filtro.setPrimeiroRegistro(first);
            filtro.setQuantidadeRegistros(pageSize);
            filtro.setPropriedadeOrdenacao(sortField);
            filtro.setAscendente(SortOrder.ASCENDING.equals(sortOrder));

            setRowCount(lancamentosTributos.quantidadeFiltrados(filtro));
            return lancamentosTributos.filtrados(filtro);
        }

        @Override
        public LancamentoTributoCdg getRowData(String rowKey) {
            for (LancamentoTributoCdg lancamento : lancamentosTributos.filtrados(filtro)) {
                if (lancamento.getId().equals(Long.parseLong(rowKey))) {
                    return lancamento;
                }
            }
            return null;
        }
        @Override
        public Object getRowKey(LancamentoTributoCdg lanccamento) {

            return lanccamento.getId();
        }
    };
}

// Datable (seleciona a linha e chama o metodo)
public void onRowSelect(SelectEvent event) {
    lancamento = (LancamentoTributoCdg) event.getObject();
    listaBancos = bancos.bancoRepository(StatusConta.ATIVA);
}

`

Browser other questions tagged

You are not signed in. Login or sign up in order to post.