Primefaces (Tabview): Null properties when saving

Asked

Viewed 231 times

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. Follows the code:

Clientescadastrados.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>
...

Clientepartialdadospessonal.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... -->

Clientepartialendereco.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... -->
...

Clientebean.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.

1 answer

1


I believe you missed processing the form. Experiment in processing 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 process="@form"

  • Thanks Marcelo, but it was not. I also tried the update but also did not work.

  • I added an add-on to the reply. see if it now works.

  • Marcelo when I started CDI Viewscoped gave error when starting Tomcat 8. I didn’t understand, because I set up context.xml and web.xml for this. You know what that can be too?

  • See if import is javax.faces.view.Viewscoped

  • Yeah, it’s like that.

  • I don’t know what it can be. I use Wildfly 10.1 I don’t know p Tomcat 8

  • 1

    Thanks Marcelo, the problem was not having put the Viewscoped even. And the mistake I was making in Tomcat when I put Viewscoped was because I wasn’t Creating the class.

Show 2 more comments

Browser other questions tagged

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