commandbutton executes method, but being null values. Why are not the inputstexts values assigned to the class attributes?

1

In all the examples I saw in the code below, the normal occurrence was when the xhtml page was started creating a new client-type object. Through the values entered in the inputs, set the attributes of this object and the commandbutton could use this data in some way, invoking a method. This is not happening in the code below. Why?

JSF Code:

 <p:panel id="dados-cliente" header="Dados do Cliente">
      <h:form>
           <p:panelGrid id="dados-cliente-container" columns="2">
                <p:outputLabel value="CNPJ:"/>
                <p:inputMask mask="##.###.###/####-##" value="# {clienteMB.cliente.cnpj}"/>
                <p:outputLabel value="Razão Social:"/>
                <p:inputText value="#{clienteMB.cliente.razao_social}"/>
                <p:commandButton action="#{clienteMB.Salvar}" value="Salvar" process="@this"/>
           </p:panelGrid>
      </h:form>
  </p:panel>

Java code:

@ManagedBean
public class ClienteMB {
    Cliente cliente;

    public ClienteMB(){
        cliente = new Cliente();
    }

    public Cliente getCliente() {
        return cliente;
    }

    public void setCliente(Cliente cliente) {
        this.cliente = cliente;
    }

    public void Salvar(){
        System.out.println(cliente.getRazao_social());
        System.out.println(cliente.getCnpj());
    }

}
    
asked by anonymous 30.08.2015 / 15:27

1 answer

1

The problem is that your <p:button> has the process="@this" attribute. This means that in the AJAX request that is made, only it is processed.

In order for the other inputs of your form to be processed and the values assigned to Bean you need to change the attribute process to process="@form" or being more restrictive process="dados-cliente-container" .

    
30.08.2015 / 18:25