Addition to an autocomplete

Asked

Viewed 39 times

0

I have an autocomplete with the code below.

<p:outputLabel styleClass="rotulos" value="Fornecedor:" />
        <p:autoComplete id="inputfornecedor" update="msgcontapagar"
            value="#{contapagarBean.object.fornecedor}" effect="fold" completeMethod="#{contapagarBean.completeFornecedor}"
             converter="fornConverter">             
        </p:autoComplete>

I am looking for a way in case the vendor does not match any listed pop up a button suspended with the option to add it.

1 answer

0


You can define in your controller (Managedbean) an attribute of the Boolean type. When you perform a search and the results come empty, you set this attribute to false.

private Boolean fornecedorExiste = true;//<--
private String fornecedorSelecionado;

public List<String> completeText(String query) {
    fornecedorExiste = true;
    FornecedorDao dao = new FornecedorDao();
    List<String> results = dao.listar(query);
    if (results.isEmpty()) {
        fornecedorExiste = false;//<--
    }
    return results;
}

And links this attribute to the rendered commandButton

<p:outputPanel autoUpdate="true">
    <p:commandButton id="btnNovo" value="Novo"
                rendered="#{not testeControl.fornecedorExiste}" />
</p:outputPanel>

So whenever there are no results to return (the searched provider does not exist) the button will be rendered.

Browser other questions tagged

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