FilterBy Primefaces (DataTable)

6 respostas
victorgilc

Olá Pessoal, boa dia!

Tentei implementar o filterby, porém, quando executo o
projeto ele simplesmente não demonstra nenhuma ação
ao tentar “filtrar” algo
O que estaria errado?

segue o codigo

<p:dataTable id="tabelaMovimento" var="item" value="#{movimentoControle.listaMovimento}" rows="9" 
                    selectionMode="single" selection="#{movimentoControle.pegaSelecionado}"
                    paginator="true"  paginatorPosition="top" emptyMessage="Nenhum registro encontrado"  
                    onRowSelectComplete="testeDialog.show()" onRowSelectUpdate="display"> 
           
          <f:facet name="header">  
             <p:outputPanel>  
                 <h:outputText value="Search all fields:" />  
                 <p:inputText id="globalFilter" filterEvent="onkeyup" update="frm:dlgMovimentos; frm:tabelaMovimento" onkeyup="formulario.tabelaMovimento.filter()"/>  
             </p:outputPanel>  
         </f:facet>  
                    
         <p:column sortBy="#{item.id}" filterBy="#{item.id}" ajax="false">  
            <f:facet name="header">  
                 <h:outputText value="ID" />  
             </f:facet>  
             <h:outputText value="#{item.id}" />  
         </p:column>

          <p:column sortBy="#{item.idCliente}" filterBy="#{item.idCliente}">  
              <f:facet name="header">  
                     <h:outputText value="ID Cliente" />  
              </f:facet>  
              <h:outputText value="#{item.idCliente}" />  
          </p:column>
           <p:column sortBy="#{item.nomeCliente}" filterBy="#{item.nomeCliente}">   
             <f:facet name="header">  
                     Cliente
             </f:facet>  
             <h:outputText value="#{item.nomeCliente}" />  
         </p:column>  
</p:dataTable>

Obrigado :wink:

6 Respostas

Takeshi91

victorgilc:
Olá Pessoal, boa dia!

Tentei implementar o filterby, porém, quando executo o
projeto ele simplesmente não demonstra nenhuma ação
ao tentar “filtrar” algo
O que estaria errado?

segue o codigo

<p:dataTable id="tabelaMovimento" var="item" value="#{movimentoControle.listaMovimento}" rows="9" 
                    selectionMode="single" selection="#{movimentoControle.pegaSelecionado}"
                    paginator="true"  paginatorPosition="top" emptyMessage="Nenhum registro encontrado"  
                    onRowSelectComplete="testeDialog.show()" onRowSelectUpdate="display"> 
           
          <f:facet name="header">  
             <p:outputPanel>  
                 <h:outputText value="Search all fields:" />  
                 <p:inputText id="globalFilter" filterEvent="onkeyup" update="frm:dlgMovimentos; frm:tabelaMovimento" onkeyup="formulario.tabelaMovimento.filter()"/>  
             </p:outputPanel>  
         </f:facet>  
                    
         <p:column sortBy="#{item.id}" filterBy="#{item.id}" ajax="false">  
            <f:facet name="header">  
                 <h:outputText value="ID" />  
             </f:facet>  
             <h:outputText value="#{item.id}" />  
         </p:column>

          <p:column sortBy="#{item.idCliente}" filterBy="#{item.idCliente}">  
              <f:facet name="header">  
                     <h:outputText value="ID Cliente" />  
              </f:facet>  
              <h:outputText value="#{item.idCliente}" />  
          </p:column>
           <p:column sortBy="#{item.nomeCliente}" filterBy="#{item.nomeCliente}">   
             <f:facet name="header">  
                     Cliente
             </f:facet>  
             <h:outputText value="#{item.nomeCliente}" />  
         </p:column>  
</p:dataTable>

Obrigado :wink:

Mas aonde isto ocorre, quando voce tentar filtrar por qual coluna?

Eu uso primefaces mas particularmente não gostei do visual deste filtro. Então implementei meu próprio filtro.

Mas aquele ajax=“false”, creio eu, que vá executar um submit() no seu formulario.

victorgilc

Em qualquer coluna,
Há alguma configuração adicional no bean
além de colocar o filterBy?

Takeshi91

Não, mas muita coisa pode influencia nisso.

A sua View está travando?

Qual navegador está à testar sua aplicação?

Poste sua managedBean e toda sua view.

victorgilc

Ok, Uso o firefox/chrome e em ambos isso ocorre
a view funciona perfeitamente, exceto pelo fato do filter não funcionar

segue o código:

A view

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ezcomp="http://java.sun.com/jsf/composite/ezcomp"
>
   <p:dialog id="dlgMovimentos" header="Movimentos Cadastrados" resetPagination="true" lazy="true" widgetVar="dlgMovimentos" width="1200" resizable="false"> 
       <p:dataTable id="tabelaMovimento" var="item" value="#{movimentoControle.listaMovimento}" rows="9" 
                    selectionMode="single" selection="#{movimentoControle.pegaSelecionado}"
                    paginator="true"  paginatorPosition="top" emptyMessage="Nenhum registro encontrado"  
                    onRowSelectComplete="testeDialog.show()" onRowSelectUpdate="display"> 
           
          <f:facet name="header">  
             <p:outputPanel>  
                 <h:outputText value="Search all fields:" />  
                 <p:inputText id="globalFilter" filterEvent="onkeyup" update="frm:dlgMovimentos; frm:tabelaMovimento" onkeyup="formulario.tabelaMovimento.filter()"/>  
             </p:outputPanel>  
         </f:facet>  
                    
         <p:column sortBy="#{item.id}" filterBy="#{item.id}">  
            <f:facet name="header">  
                 <h:outputText value="ID" />  
             </f:facet>  
             <h:outputText value="#{item.id}" />  
         </p:column>

          <p:column sortBy="#{item.idCliente}" filterBy="#{item.idCliente}">  
              <f:facet name="header">  
                     <h:outputText value="ID Cliente" />  
              </f:facet>  
              <h:outputText value="#{item.idCliente}" />  
          </p:column>
           <p:column sortBy="#{item.nomeCliente}" filterBy="#{item.nomeCliente}">   
             <f:facet name="header">  
                     Cliente
             </f:facet>  
             <h:outputText value="#{item.nomeCliente}" />  
         </p:column>  

         <p:column sortBy="#{item.ficha}">  
             <f:facet name="header">  
                     Ficha 
             </f:facet>  
             <h:outputText value="#{item.ficha}" />  
         </p:column> 

        <p:column sortBy="#{item.numeroParcela}">  
             <f:facet name="header">  
                     Parcela 
             </f:facet>  
            <h:outputText value="#{item.numeroParcela}" />  
         </p:column> 

        <p:column sortBy="#{item.tipoMovimento}">  
             <f:facet name="header">  
                     Tipo Movimento
             </f:facet>  
            <h:outputText value="#{item.tipoMovimento}" />  
         </p:column> 

        <p:column sortBy="#{item.valor}">  
             <f:facet name="header">  
                     Valor
             </f:facet>  
             <h:outputText value="#{item.valor}" />  
         </p:column> 

        <p:column sortBy="#{item.juros}">  
             <f:facet name="header">  
                     Juros
             </f:facet>  
            <h:outputText value="#{item.juros}" />  
         </p:column> 

        <p:column sortBy="#{item.saldo}">  
             <f:facet name="header">  
                     Saldo
             </f:facet>  
             <h:outputText value="#{item.saldo}" />  
         </p:column> 

        <p:column sortBy="#{item.data}">  
             <f:facet name="header">  
                     Data
             </f:facet>  
            <h:outputText value="#{item.data}" />  
         </p:column> 

        <p:column sortBy="#{item.tipoPagamento}">  
             <f:facet name="header">  
                     Tipo Pagamento
             </f:facet>  
            <h:outputText value="#{item.tipoPagamento}" />  
         </p:column> 
       </p:dataTable>  
          
          <br/>

            <div style="margin-right: 5px; float: left">
                <h:selectOneMenu value="Teste" style="width: 300px">
                    <f:selectItem itemLabel="1" itemValue="1"/>
                    <f:selectItem itemLabel="2" itemValue="1"/>
                </h:selectOneMenu>
            </div>                               
            <div style="margin-right: 5px; float: left">
                <h:selectOneMenu value="Teste" style="width: 250px">
                    <f:selectItem itemLabel="1" itemValue="1"/>
                    <f:selectItem itemLabel="2" itemValue="1"/>
                </h:selectOneMenu>                                  
            </div>

            <div style="margin-right: 5px; float:left">
                <p:inputText value="" style="width: 272px"/>                                  
            </div>

            <div style="margin-right: 8px; float:left" onclick="frm:dlgCadastroMovimentos.show();">
                <p:commandLink style="width: 25px;height: 25px" >
                    <p:graphicImage alt="imagem" value="/imagens/adicionar16x16.png" style="border: 0"/>
                </p:commandLink>          
            </div>
            <div style="margin-right: 11px; float:left">
                <p:commandLink style="width: 25px;height: 25px" >
                    <p:graphicImage alt="imagem" value="/imagens/abrir.png" style="border: 0"/>
                </p:commandLink>           
            </div>
          <div style="margin-right: 11px; float:left">
              <p:commandLink style="width: 25px;height: 25px" onclick="testeDialog.show()" update="frm:display" >
                    <p:graphicImage alt="imagem" value="/imagens/remover16x16.png" style="border: 0"/>
                    <f:param id="excl" name="codigo" value="#{movimentoControle.pegaSelecionado.id}"/>
                </p:commandLink>                     
            </div>
                
       <p:dialog header="teste" widgetVar="testeDialog" resizable="false"  
               width="200">  
   
         <h:panelGrid id="display" columns="2" cellpadding="4">  
   
            
   
             <h:outputText value="ID:" />  
             <h:outputText value="#{movimentoControle.pegaSelecionado.id}" />  
   
             <h:outputText value="Nome Cliente:" />  
             <h:outputText value="#{movimentoControle.pegaSelecionado.nomeCliente}" />  
    
         </h:panelGrid>  
     </p:dialog>  
              
                
            <div style="margin-right: 11px; float:left">
                <p:commandLink style="width: 25px;height: 25px" >
                    <p:graphicImage alt="imagem" value="/imagens/atualizar.png" style="border: 0"/>
                </p:commandLink>              
            </div>
            <div style="margin-right: 11px; float:left">
                <p:commandLink style="width: 25px;height: 25px" >
                    <p:graphicImage alt="imagem" value="/imagens/add-16.png" style="border: 0"/>
                </p:commandLink>           
            </div>
            <div style="margin-right: 11px; float:left">
                <p:commandLink style="width: 25px;height: 25px" >
                    <p:graphicImage alt="imagem" value="/imagens/add-16.png" style="border: 0"/>
                </p:commandLink>               
            </div>

            <div style="margin-right: 5px; float:left">
                <p:inputText value="" style="width: 150px"/>                                  
            </div>
        </p:dialog>   
</html>

O bean:

package controle;

import java.sql.SQLException;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import modeloMovimento.DadosBancoMovimento;
import modeloMovimento.Ficha;
import modeloMovimento.Movimento;
import modeloMovimento.Pagamento;
import modeloMovimento.ModeloTabelaMovimento;

/**
 *
 * @author victor
 */
@ManagedBean
@SessionScoped
public class MovimentoControle {

    private DAOMovimento.MovimentoDAO movimentoDao;
    private modeloMovimento.Movimento movimento;
    private Ficha ficha;
    private Pagamento pagamento;
    private DadosBancoMovimento dadosBancoMovimento;
    private List<ModeloTabelaMovimento> listaMovimento;


    public MovimentoControle() {
        movimentoDao = new DAOMovimento.MovimentoDAO();
        movimento = new modeloMovimento.Movimento();
        ficha = new Ficha();
        pagamento = new Pagamento();
        dadosBancoMovimento = new DadosBancoMovimento();        
    }

    public DadosBancoMovimento getDadosBancoMovimento() {
        return  dadosBancoMovimento;
    }

    public void setDadosBancoMovimento(DadosBancoMovimento dadosBancoMovimento) {
        this.dadosBancoMovimento =  dadosBancoMovimento;
    }

    public Ficha getFicha() {
        return ficha;
    }

    public void setFicha(Ficha ficha) {
        this.ficha = ficha;
    }

    public Movimento getMovimento() {
        return movimento;
    }

    public void setM(Movimento movimento) {
        this.movimento = movimento;
    }

    public DAOMovimento.MovimentoDAO getmovimentoDao() {
        return movimentoDao;
    }

    public void setmovimentoDao(DAOMovimento.MovimentoDAO movimentoDao) {
        this.movimentoDao = movimentoDao;
    }

    public Pagamento getPagamento() {
        return pagamento;
    }

    public void setP(Pagamento pagamento) {
        this.pagamento = pagamento;
    }

    public List<ModeloTabelaMovimento> getListaMovimento() throws SQLException, ClassNotFoundException {
        if (listaMovimento == null) {
            listaMovimento = movimentoDao.getMovimentosCadastrados();
        }
        return listaMovimento;
    }
    
    public void exclui() throws SQLException, ClassNotFoundException {
        FacesContext context = FacesContext.getCurrentInstance();

        HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();

        System.out.println("Busca: " + req.getParameter("codigo"));

        movimentoDao.exclui(req.getParameter("codigo"));
    }   
}
Takeshi91

Estou resolvendo uns problemas no meu sistema. Depois darei uma olhada no seu código.

victorgilc

Ok, fico aguardando, vlw!

Criado 31 de março de 2011
Ultima resposta 31 de mar. de 2011
Respostas 6
Participantes 2