Addition in an autocomplete

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'm looking for a way to case the vendor does not match any listed popup a popup button with the option to add it.

    
asked by anonymous 21.06.2016 / 20:00

1 answer

0

You can set a Boolean attribute on your controller (ManagedBean). 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 binds this attribute to the rendered commandButton

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

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

    
22.06.2016 / 02:15