I've a data table with editMode="cell". My problem is when I edit a cell (in either one of the editable columns), submit it, go to the listener method, and try to obtain the modified value using:
event.getNewValue()
It's not reflecting the edited value. It actually always returns the old value. Consequently the bean doesn't get updated. Any clues of what I'm doing wrong? I'm using JavaServer Faces 2.2, Primefaces 5.0 and Spring Framework 4.0.3.
Thanks for any help.
Here's the XHTML code:
<p:dataTable id="nieoTable" var="nieo" value="#{nieoController.nieos}"
editable="true" editMode="cell" widgetVar="cellNieo"
selectionMode="single" selection="#{nieoController.selectedNieo}"
rowKey="#{nieo.nieoNumber}" tableStyle="width:auto">
<p:ajax event="rowSelect" update=":nieoForm:wasIsGrid :nieoForm:paperModsumGrid :nieoForm:effectivityGrid" />
<p:ajax event="cellEdit" listener="#{nieoController.onEditNieo}" update=":nieoForm:nieoTable :nieoForm:growl" />
<p:column headerText="Nieo Number">
<h:outputText value="#{nieo.nieoNumber}" />
</p:column>
<p:column headerText="PLM Action Number">
<p:cellEditor>
<f:facet name="output">
<h:outputText id="plmActionNumberOutput" value="#{nieo.plmActionNumber}" />
</f:facet>
<f:facet name="input">
<h:inputText id="plmActionNumberInput" value="#{nieo.plmActionNumber}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="SAP Change Master">
<p:cellEditor>
<f:facet name="output">
<h:outputText id="sapChangeMasterOutput" value="#{nieo.sapChangeMaster}" />
</f:facet>
<f:facet name="input">
<h:inputText id="sapChangeMasterInput" value="#{nieo.sapChangeMaster}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Command">
<p:commandButton title="Remove NIEO" icon="ui-icon-trash"
actionListener="#{nieoController.deleteNieo(nieo)}"
update=":nieoForm:nieoTable :nieoForm:growl" />
</p:column>
</p:dataTable>
Here's the code for the managed bean (controller):
public class NieoController {
@Autowired
private NIEOService nieoService;
public void onEditNieo(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
if(newValue != null && !newValue.equals(oldValue)) {
FacesContext context = FacesContext.getCurrentInstance();
NIEO nieo = context.getApplication().evaluateExpressionGet(context, "#{nieo}", NIEO.class);
nieoService.updateNieo(nieo);
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Nieo updated", "Old: " + oldValue + ", New:" + newValue);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}