PrimeFaces 6.2 onCellEdit - getNewValue () nn is receiving the new value

0

I'm doing a project with PrimeFaces and on a screen I use a DataTable with cellEdit and I followed the showcase example right and tals however the getNewValue and the getOldValue are coming null and this is breaking my application, to follow the code:

onCellEdit Method:

public void onCellEdit(CellEditEvent event) {
    Object valorAntigo = event.getOldValue();
    Object valorNovo = event.getNewValue();

    if (valorNovo != null && !valorNovo.equals(valorAntigo)) { //ele nao esta entrando neste IF pq os valores estão nulos
        if (editEmItemSelecionado(Long.parseLong(event.getRowKey())) && !existeItemNaLista(Long.parseLong(event.getRowKey()))) {
            Item item = new Item();
            item.setIdItem(Long.parseLong(event.getRowKey()));
            item.setQuantidade((Short)valorNovo);
            quantidades.add(item);
        }
    }
}

Screen:

<p:dataTable id="lista" value="#{itemController.getDataModelCliente(p.idCategoria)}" var="i" selection="#{itemController.itensSelecionados}" editable="true" editMode="cell">
                <p:ajax event="cellEdit" update="lista" process="@this" partialSubmit="true" listener="#{itemController.onCellEdit}"/>

                <p:column selectionMode="multiple" style="text-align: center">
                </p:column>

                <p:column headerText="Item">
                    <h:outputText value="#{i.nomeItem}"/>
                    <br/>
                    <h:outputText value="#{i.descricao}" rendered="#{i.descricao != null}"/>
                    <h:outputText value="N/A" rendered="#{i.descricao.equalsIgnoreCase(null)}"/>
                    <br/>
                    <h:outputText value="N/A" rendered="#{i.tempoPreparo == 0}"/>
                    <h:outputText value="#{i.tempoPreparo} Minutos" rendered="#{i.tempoPreparo != 0}"/>
                </p:column>

                <p:column headerText="Preço">
                    <h:outputText value="R$ #{i.preco}" rendered="#{i.categoria.idCategoria.equals(p.idCategoria)}"/>
                </p:column>

                <p:column headerText="Quantidade">
                    <p:cellEditor>
                        <f:facet name="output"> <h:outputText value="#{i.quantidade}"/> </f:facet>
                        <f:facet name="input"> <p:spinner value="#{i.quantidade}" min="1"/> </f:facet>
                    </p:cellEditor>
                </p:column>
            </p:dataTable>

Looking at the internet I noticed that there are more people with this same problem than I or similar but nn found an answer yet, at least I did not find one that works for me, can anyone help me?

Edit 1:

I was wondering what's happening is that it's not sending the new value and so it was null because the old value was null, but I still have not solved the problem, I can not receive the new value, Why?

    
asked by anonymous 09.09.2018 / 06:11

1 answer

0

I found my error, the error is in line <p:dataTable id="lista" value="#{itemController.getDataModelCliente(p.idCategoria)}"... I'm only using the method get of my DataModel object. The good part is that I found the error, the bad part is that my logic was pro bag because I was doing (I know DataTable is already dynamic) a DataTable "more dynamic", it is difficult to explain but only you read the code maybe you'll understand what I'm trying to say, I'll have to think of another logic here, flw!

    
10.09.2018 / 04:46