0
I’m doing a project with Primefaces and on a screen I use a Datatable with cellEdit and I followed the example of the right showcase and tals however the getNewValue
and the getOldValue
are coming up null and this is breaking my application, following the code:
Method onCellEdit:
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);
}
}
}
Canvas:
<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 on the internet I realized that there are more people with this same problem that I or similar but nn found an answer yet, at least not found one that works for me, someone can help me?
Edit 1:
Perrcebi what is happening is that he nn ta sending the new value and so he was coming null because the old value was null, but still nn solved the problem, I nn can receive the new value, someone knows why?