Update an h:outputText from a p:autocomplete database

Asked

Viewed 238 times

1

I have a medical care application and I have the following question: when to use the component p:autoComplete of Primefaces to search for the name of the patient who has the attribute dataNascimento, I want the h:outputText get the age from the database.

<p:autoComplete id="nome"
                value="#{cadastroPrimeiraConsultaBean.pessoa.nome}" 
                completeMethod="#{cadastroPrimeiraConsultaBean.porNome}"  
                var="pessoa" itemLabel="#{pessoa.nome}" itemValue="#{pessoa}"
                forceSelection="true" dropdown="true" />

<p:outputLabel value="Data de Nascimento:" for="dataNascimento" />
                <h:outputText  value="cadastroPrimeiraConsultaBean.pessoa.dataNascimento id="dataNascimento"/>

Could you help me solve this problem.

inserir a descrição da imagem aqui

1 answer

1

Try adding to your autocomplete:

<p:ajax event="itemSelect" update="IDdoOutPutText" process="@this"/>

If you do not set the patient, add a Systener to set the patient in your bean in that same ajax.

  • Rafael, to do this Switch, I have to pick up the id? Example: public Pessoa porId(Long id) { Return manager.find(Person.class, id); }

  • Yes, I would recommend doing by id.

  • <p:outputLabel value="Patient’s Name:" for="patient" /> <p:autocomplete placeholder="Enter patient’s name" id="patient" value="#{cadastre PrimeiraConsultaBean.primeiraConsulta.person}" completeMethod="#{cadastralPrimeiraConsultaBean.completeName}" var="patient" itemLabel="#{patient.name}" itemValue="#{patient}" forceSelection="true" dropdown="true" > <p:ajax Event="itemSelect" update="ready" process="@this" Listener="#{cadastre>

Browser other questions tagged

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