Primefaces autocomplete does not pass value to the bean

Asked

Viewed 442 times

1

I have a problem with the Primefaces autocomplete component. The value parameter is not being passed to my bean.

private String filtroClientes;

public List<String> listarFiltroDeClientes()
{
    List<String> lista = new ArrayList<String>();
    List<Cliente> clientesFiltrados = Clientes.buscarPorPartesDoNome(filtroClientes);


    for(int  i = 0; i < clientesFiltrados.size(); i++)
    {
        lista.add(clientesFiltrados.get(i).getNomeCliente());
    }

    return lista;

}

public String getFiltroClientes() {
    return filtroClientes;
}

public void setFiltroClientes(String filtroClientes) {
    this.filtroClientes = filtroClientes;
}

<p:autoComplete id="acCliente" value="#{projetosBean.filtroClientes}" 
							completeMethod="#{projetosBean.listarFiltroDeClientes()}"/>

When you print "filterClose" it shows the null value, or whatever was typed in the autocomplete input is not passing to the bean. Other than that the component is working normally, I have tested pass any string to filter the customers and the component worked.

Who can help already thank you. Thanks!!

  • created a get method for filterClients ?

  • Yes I created the methods, interesting that if I start the variable with some value, it takes that value no longer updates it, that is to say get works the set does not.

  • 1

    Did you ever see the example there in the prime showcase? i haven’t used JSF anymore but in all examples I’ve seen it get in the listFiltroDeClient() method a String query ex: listFiltroDeClient(String query) to concatenate with the name ex: list.add(query + clientsFiltered.get(i).getNomeClient()); Another detail is that they do not use constructor in EL ex: completeMethod="#{projectsBean.listFiltroDeClients}" see: Auto Complete

  • What is the Scopo of your managerbean ? See if you have Viewscope.

1 answer

1

The error is in completeMethod:

<p:autoComplete id="acCliente" value="#{projetosBean.filtroClientes}" 
                        completeMethod="#{projetosBean.listarFiltroDeClientes()}"/>

You do not use "()" calling mbean methods. Change to:

<p:autoComplete id="acCliente" value="#{projetosBean.filtroClientes}" 
                        completeMethod="#{projetosBean.listarFiltroDeClientes}"/>

The way your method of completing was not even called, so the value was not set in value. With this change should work.

Browser other questions tagged

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