Filling in automatic data - JSF

Asked

Viewed 394 times

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();
    }
}

1 answer

1


  • 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 used Primefaces apparently

  • 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 attribute update.

  • you are correct

Browser other questions tagged

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