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

Asked

Viewed 268 times

1

In all the examples I saw of the code below, the normal one was to start the xhtml page to create a new client-like 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. Because?

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());
    }

}

1 answer

1


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

So that the rest inputs of your form are processed and the values assigned to Bean you need to change the attribute process for process="@form" or being more restrictive process="dados-cliente-container".

Browser other questions tagged

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