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?