Update datatable

Asked

Viewed 455 times

0

I’m having trouble updating a primafaces datatable after doing a filterBy search. First, I do a search through a method in managedbean to bring the list from the bank to the table. Therefore, I search through a column using the filterBy attribute. After that, when I perform another search by managedbean the list of results in the datatable is not updated anymore, continue the same results of the previous search.

Below the button that performs research:

 <p:commandButton value="Pesquisar" 
                   actionListener="#{notificacaoManagedBean.filtrarNotificacoes()}"  
                                     update=":form:formAlarmesEventos:listaNotificacao" 
                                     ajax="true"
                                     process="@all"
                                     icon="ui-icon-search">
                    </p:commandButton> 

A datatable:

<p:dataTable
                widgetVar="dataTableNotificacao"
                value="#{notificacaoManagedBean.notificacoes}"
                var="notificacao"
                id="listaNotificacao"
                paginator="true"
                rows="10"
                rowsPerPageTemplate="5, 10, 15, 20, 30, 50, 100"
                emptyMessage="Nenhuma notificação foi registrada."
                style="width: 100%" >

                <f:facet name="header">Lista de Notificações</f:facet>

                <p:column headerText="Hora e Data">
                    <h:outputText value="#{notificacao.dataHora}">
                        <f:convertDateTime pattern="HH:mm:ss - dd/MM/yyyy" />
                    </h:outputText>
                    <ui:remove>
                        <h:outputText value="#{notificacao.dataHora}" styleClass="dataInibida">
                            <f:convertDateTime locale="pt_BR" />
                        </h:outputText>
                    </ui:remove>
                </p:column>

                <p:column  width="8%" filterBy="#{notificacao.tipo}" headerText="Tipo" filterMatchMode="exact">
                    <f:facet name="filter"  >
                        <p:selectOneMenu id="selectTipo" onchange="PF('dataTableNotificacao').filter()"  >
                            <f:selectItem itemLabel="Tudo" itemValue="#{null}"  />
                            <f:selectItem itemValue="Evento" itemLabel="Eventos" />
                            <f:selectItem itemValue="Alarme" itemLabel="Alarmes" />
                        </p:selectOneMenu>
                    </f:facet>
                    <h:outputText id="map" value="#{notificacao.tipo}" />
                </p:column>

                <p:column headerText="Tag" filterBy="#{notificacao.tag}" >#{notificacao.tag}</p:column>
                <p:column headerText="Operador" filterBy="#{notificacao.operador}" >#{notificacao.operador}</p:column>
                <p:column headerText="Computador">#{notificacao.computador}</p:column>
                <p:column headerText="Valor Anterior" width="7%" >#{notificacao.valorAnterior}</p:column>
                <p:column headerText="Valor Atual" width="7%" >#{notificacao.valorAtual}</p:column>
            </p:dataTable> 

The method that filters the search:

 public void filtrarNotificacoes(){
    notificacoes = new ArrayList<>();
    notificacao = new Notificacao();

    Date inicio = DateHelper.unirDataHora(dataInicial, horaInicial);
    Date fim = DateHelper.unirDataHora(dataFinal, horaFinal);

    notificacoes = service.obterNotificacoes(
            new DateHelper(inicio),
            new DateHelper(fim));
}
  • opa, blz, tries to debug and see what returns in the notification variable when you press the button...

  • Opa Raphão, get the notification list correctly.

  • Ever tried to clean the project? Sometimes it solves

  • Post your full xhtml please. Edit the question.

No answers

Browser other questions tagged

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