Why is my Bean not getting the form Ubmit?

Asked

Viewed 493 times

0

Why my Bean is not recognizing the attribute of a simple selectOneMenu: I created in my Bean the attribute private Long areaprevencaoId. This attribute is associated with a <p:selectOneMenu>

xhtml

   <h:selectOneMenu value="#{cadastroUsuarioBean.areaPrevencaoId}">
        <f:selectItems value="#{cadastroUsuarioBean.listaAreaPrevencaoSelect}"></f:selectItems>
    </h:selectOneMenu>
    <p:commandButton action="#{cadastroUsuarioBean.incluirArea}" value="Incluir" 
        process="@this" update="panel-grid-equipe" immediate="true" />

My Bean that uses the attribute:

    public void incluirArea() {
    if (areaPrevencaoId == null) {
        messages.error("Selecione uma Equipe");
    } else {
        usuarioPrevencao.setUsuarioId(usuario.getId());
        usuarioPrevencao.setAreaprevencaoId(areaPrevencaoId);
        try {
            usuarioPrevencaoRepository.salvar(usuarioPrevencao);
            //this.listaUsuarioPrevencao = usuarioPrevencaoRepository.todosIdUsuario(usuario.getId());
        } catch (PersistenceException e) {
            messages.error("Erro ao gravar os dados da Equipe do Usuário");
        }
    }
    RequestContext.getCurrentInstance().update(Arrays.asList("msg-area-prevencao","painel-equipe"));
}
  • 1

    My suggestion is that you do the process of the form instead of the CommandButton, but none of the components of form will go through the jsf lifecycle and update your template (Bean).

  • Wakin made the adjustment, but it’s still going null.

  • 1

    Place @form in the attribute process?

  • Wakin, you were right. In xhtml it was all within a single form. I separated and made the process="@form" and it worked. Thanks!

  • I will put as an answer so that others can find the solution to the problem if it is the same.

2 answers

1


In that case, you should change the process="@this" for process="@form" so the whole form will be processed instead of just the button.

With the form being processed, all components within it will be and the selectOneMenu will update the template, the attribute of your Bean, with the selected value.

1

Taking into account that you are using the framework Primefaces, I also suggest that you study the following topic: Ajax Framework - PFS.

It is an implementation that allows processing (process) and update (update) of components using the API de seletores used by JQuery.

It may not be your specific case, but there are situations where your form has a large amount of components, and sending them all will only end up impacting the performance of your application.

Recommended is that you send and/or update only the required elements.

  • Romulo thanks for the tip. Hugs

Browser other questions tagged

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