updating by filling in information after using the autocomplete

Asked

Viewed 196 times

0

I am creating a form in JSF and primeface, and I have here an autocomplete. Only when I finish filling out my autocomplete, I want you to render a part of my fomulário.

Until now I was able to hide the fields, which in this case would be the panelGrid with id="informacaoClienteServico"

In my CPF it looks like this: Logico that did not render because it is still null, I want that when exiting the completed autocomplete it render my panelGrid.

@Transient
public boolean isClienteNovo() {
    return this.getCpf() == null;
}

@Transient
public boolean isClienteExistente() {
    return !isClienteNovo();
}

<ui:composition 
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui" 
xmlns:o="http://omnifaces.org/ui">

    <p:panelGrid columns="4" id="painel" style="width: 100%; margin-top: 20px" columnClasses="rotulo, campo, rotulo, campo">

        <p:outputLabel value="Cpf" for="cpf" />
        <p:autoComplete id="cpf"  value="#{cadastroServicoBean.servico.cliente}" size="13" required="true" dropdown="true"
                        completeMethod="#{cadastroServicoBean.completaCliente}" var="client" itemLabel="#{client.cpf}" 
                        forceSelection="true" minQueryLength="2" />

        <p:outputLabel value="Carro" for="carro" />
        <p:selectOneMenu id="carro" value="#{cadastroServicoBean.servico.carro}" required="true">
            <f:selectItem  itemLabel="--Selecione--" noSelectionValue="true"/>
            <f:selectItems value="#{cadastroServicoBean.carros}" var="carro" itemLabel="#{carro.modeloCarro.nome} : #{carro.placa}"  />
        </p:selectOneMenu>

        <p:outputLabel value="Data do Serviço" for="dataServico" />
        <p:calendar id="dataServico" value="#{cadastroServicoBean.servico.diaServico}"  size="13" pattern="dd/MM/yyyy" required="true" />

        <p:outputLabel value="Data da Garantia" for="dataGarantia" />
        <p:calendar id="dataGarantia" value="#{cadastroServicoBean.servico.diaGarantia}"  size="13" pattern="dd/MM/yyyy"  required="true"/>

        <p:outputLabel value="valor" for="valor" />
        <p:inputText  styleClass="moeda" value="#{cadastroServicoBean.servico.valor}"  size="5" id="valor"  required="true">
            <f:convertNumber pattern="#,##0.00" />
        </p:inputText>

        <p:outputLabel value="Pagamento" for="pagamento" />
        <p:selectOneMenu id="pagamento" value="#{cadastroServicoBean.servico.pagamento}" style="width: 138px" required="true">
            <f:selectItem itemLabel="--Selecione--" noSelectionOption="true"  />
            <f:selectItems value="#{cadastroServicoBean.pagamentos}" var="pgto" itemLabel="#{pgto.descricao}" itemValue="#{pgto}" />
        </p:selectOneMenu>

        <p:outputLabel for="statusServ"  value="Status Serviço"/>
        <p:selectOneMenu id="statusServ"  value="#{cadastroServicoBean.servico.statusServico}" style="width: 138px" required="true">
            <f:selectItem itemLabel="--Selecione--" noSelectionOption="true"/>
            <f:selectItems value="#{cadastroServicoBean.statusServicos}" var="stsServ" itemLabel="#{stsServ.descricao}" itemValue="#{stsServ}" />
        </p:selectOneMenu>

        <p:outputLabel value="Subtotal" style="font-weight:bold;" />
        <p:outputLabel style="font-weight:bold;" />

        <p:outputLabel value="desconto"  for="desc" />
        <p:inputText id="desc" value="#{cadastroServicoBean.servico.desconto}"  styleClass="moeda">
            <f:convertNumber  pattern="#,##0.00" />
        </p:inputText>

        <p:outputLabel value="Total Serviço" style="font-weight:bold;" />
        <p:outputLabel style="font-weight:bold;"  />
    </p:panelGrid>


    <p:panelGrid columns="2" id="informacaoClienteServico" rendered="#{cadastroServicoBean.cliente.clienteExistente}">
        <f:facet name="header">Informações do Cliente</f:facet>

        <p:outputLabel value="Cliente:" rendered="#{cadastroServicoBean.cliente.clienteExistente}" />
        <p:outputLabel value="#{cadastroServicoBean.servico.cliente.nome}"  rendered="#{cadastroServicoBean.cliente.clienteExistente}"/>

        <p:outputLabel value="Cliente:" rendered="#{cadastroServicoBean.cliente.clienteExistente}" />
        <p:outputLabel value="#{cadastroServicoBean.servico.cliente.nome}" rendered="#{cadastroServicoBean.cliente.clienteExistente}" />

        <p:outputLabel value="Telefone Fixo" rendered="#{cadastroServicoBean.cliente.clienteExistente}" />
        <p:outputLabel value="#{cadastroServicoBean.servico.cliente.telefoneFixo}" rendered="#{cadastroServicoBean.cliente.clienteExistente}" />

        <p:outputLabel value="Telefone Fixo" rendered="#{cadastroServicoBean.cliente.clienteExistente}" />
        <p:outputLabel value="#{cadastroServicoBean.servico.cliente.telefoneCelular}" rendered="#{cadastroServicoBean.cliente.clienteExistente}" />         
    </p:panelGrid>
<br />
<br />

1 answer

0

You can use the ajax:

<p:autoComplete id="cpf"  value="#{cadastroServicoBean.servico.cliente}" size="13" required="true" dropdown="true"
                        completeMethod="#{cadastroServicoBean.completaCliente}" var="client" itemLabel="#{client.cpf}" 
                        forceSelection="true" minQueryLength="2" >
<p:ajax event="itemSelect" update="informacaoClienteServico" listener=""/>
</p:autoComplete> 

Where is listener you create a method that will change the customer value true.

Browser other questions tagged

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