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.
Thanks Marcelo, but it was not. I also tried the update but also did not work.
– Raphael
I added an add-on to the reply. see if it now works.
– Marcelo
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?
– Raphael
See if import is javax.faces.view.Viewscoped
– Marcelo
Yeah, it’s like that.
– Raphael
I don’t know what it can be. I use Wildfly 10.1 I don’t know p Tomcat 8
– Marcelo
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.
– Raphael