Primefaces (TabView): Null properties when saving

0

I'm using a TabView with two tabs and each tab with an external file with fields. By clicking the "Save" button the attributes are coming as null. Here is the code:

Registered Clients.xhtml:

...
<h:form id="frm-cadastro-cliente-dialog">
    <p:dialog header="Cadastrar Cliente" widgetVar="cadastroClienteDialog">
        <p:tabView>
            <p:tab title="Dados Pessoais">
                <h:panelGrid columns="2">
                    <ui:include src="/WEB-INF/cliente/ClientePartialDadosPessoais.xhtml" />
                </h:panelGrid>
            </p:tab>

            <p:tab title="Endereço">
                <h:panelGrid columns="2">
                    <ui:include src="/WEB-INF/cliente/ClientePartialEndereco.xhtml" />
                </h:panelGrid>
            </p:tab>
        </p:tabView>

        <p:commandButton value="Salvar" action="#{clienteBean.salvar}"/>
    </p:dialog>    
</h:form>
...

ClientPartialDadosPersonal.xhtml:

...
<p:outputLabel value="Nome" for="nome" />
<p:inputText id="nome" required="true" value="#{clienteBean.cliente.nome}" />

<p:outputLabel value="E-mail" for="email" />
<p:inputText id="email" value="#{clienteBean.cliente.email}" />

<!--  outros campos... -->

ClientPartialEndereco.xhtml:

...
<p:outputLabel value="Logradouro" for="logradouro" />
<p:inputText id="logradouro" value="#{clienteBean.cliente.logradouro}" />

<p:outputLabel value="Complemento" for="complemento" />
<p:inputText id="complemento" value="#{clienteBean.cliente.complemento}" />

<!--  Outros campos... -->
...

ClientBean.java:

@Named
@RequestScoped
public class ClienteBean {

    @Inject
    private Cliente cliente;

    public void salvar() {
        System.out.println("Nome: " + cliente.getNome()); //null
        System.out.println("E-mail: " + cliente.getEmail()); //null
        System.out.println("Logradouro: " + cliente.getLogradouro()); //null
        System.out.println("Complemento: " + cliente.getComplemento()); //null
        ...
    }
}

Note: I am using CDI.

    
asked by anonymous 27.02.2017 / 20:13

1 answer

1

I believe you have not processed the form. Try not to process the form Ex

<p:commandButton value="Salvar" action="#{clienteBean.salvar}" process="@form"/>

It may also be scope problem, try switching to @ViewScoped from javax.faces.view.ViewScoped instead of @RequestScoped. And keep the process="@ form"

    
01.03.2017 / 14:11