0
I need to have my inputs filled automatically, after selecting the combo. I have done the method to go through the database and retrieve the necessary information, but does not fill... Can anyone help me? I think due to the ajax update, but I don’t know how to update the form...
index.xhtml
<h:form id="formGeral" prependId="false">
<h:panelGrid id="panelDados" columns="4" cellpadding="8">
<p:outputLabel class="lt" value="Projeto:" />
<p:selectOneMenu value="#{usuarioBean.projeto.codigo}"
required="true" requiredMessage="O campo 'Projeto' é obrigatório.">
<f:selectItem itemLabel="Selecione o projeto" itemValue="" />
<f:selectItems value="#{projetoBean.projetos}" var="projeto"
itemLabel="#{projeto.projeto}" itemValue="#{projeto.codigo}" />
<f:ajax listener="#{usuarioBean.popularProjeto}"
update=":formGeral" />
</p:selectOneMenu>
<p:outputLabel class="lt" value="Superior Imediato:" />
<p:inputText id="superiorImediato"
value="#{usuarioBean.recebeSuperior}" />
<p:outputLabel class="lt" value="Tipo projeto:" />
<p:inputText id="tipoProjeto"
value="#{usuarioBean.recebeTipoProjeto}" />
</h:panelGrid>
</h:form>
method to recover data:
public void popularProjeto() {
try {
if (projeto != null) {
Projeto recebeProjeto = projetoDAO.buscarPorCodigo(projeto.getCodigo());
recebeSuperior = recebeProjeto.getProjeto();
recebeTipoProjeto = recebeProjeto.getTipo();
System.out.println(recebeSuperior);
System.out.println(recebeTipoProjeto);
}
} catch (Exception e) {
e.printStackTrace();
}
}
I believe that what the user wants, is to update the components when selecting a value in the combo, so it would be to give a
update
, agree? Also there is another detail, is usedPrimefaces
apparently– Macario1983
Hello Macario1983, would be yes
update
if the tag used was<p:ajax>
but the tag used in the example is the<f:ajax>
which does not have the attributeupdate
.– Jose Anderson Pereira
you are correct
– Macario1983