Rodrigo Cavalcante
Rodrigo Cavalcante

Reputation: 1597

JSF 2.2 @ViewScoped binding bug?

I've read about the binding bug with @ViewScoped (BUG REPORT) and that it was fixed in one of the latest versions of JSF, so I tested this with the 3 latest versions of JSF and tried using the

  <context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>

fix to solve it, but no luck.

I have a primefaces datatable where I have filters in each column header.

        <p:column id="cpfHeader" sortBy="#{cliente.nrCpf}"
        filterMatchMode="contains">
        <f:facet name="header">
            <h:panelGrid columns="1">
                <h:outputText value="CPF" />
                <p:inputText value="#{cadastroClienteBean.cliente.nrCpf}">

                </p:inputText>
                <p:commandButton
                    actionListener="#{cadastroClienteBean.getClientesBusca}"
                    update="#{form}:tabelaCliente:tblCliente" value="Filtrar"></p:commandButton>
            </h:panelGrid>
        </f:facet>
                #{cliente.nrCpf}                
            </p:column>

Before I changed the JSF version, everytime I'd click on the "Filtrar" button, a new instance of my cadastroClienteBean would be created. Now that I've changed it, it seems that the ManagedBean is not being instantiated everytime, but the cliente variable is becoming null, eventhough I instantiate it on the constructor.

    public CadastroClienteBean(){
    cliente = new Cliente();
    init();
}

EDIT: After debugging a bit I found out that the value of the filter is being set on the variable and right after that the setCliente() is being called and setting it to null, but I don't know why.

Upvotes: 1

Views: 1515

Answers (1)

Rodrigo Cavalcante
Rodrigo Cavalcante

Reputation: 1597

Figured out what was happening the selection="#{cadastroClienteBean.cliente}" attribute on the dataTable was setting the client to null since there was no line selected.

Upvotes: 1

Related Questions