Why is not my Bean receiving the submit form?

0

Why my Bean is not recognizing the attribute of a simple selectOneMenu: I created in my Bean the private Long areaprevencaoId attribute. 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"));
}
    
asked by anonymous 14.10.2015 / 02:03

2 answers

1

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

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

    
14.10.2015 / 03:04
1

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

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

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

It is recommended that you submit and / or update only the required elements.

    
14.10.2015 / 04:04