Search code examples
jsfprimefacestablecelleditor

Primefaces Celleditor event doesn't contain new value


I want to use the PF 4 celleditor and sticked to the example in the showcase. But I get the following behavior: I can edit my cell, the onCellEdit() inside the bean is called, but the event will contain the old value for event.getNewValue(). Listening to the network traffic, I was able to catch this:

javax.faces.partial.ajax=true&
javax.faces.source=pvChangeForm%3Apvc&
javax.faces.partial.execute=pvChangeForm%3Apvc&
javax.faces.partial.render=pvChangeForm%3Apvc+pvForm&
javax.faces.behavior.event=cellEdit&
javax.faces.partial.event=cellEdit&
pvChangeForm%3Apvc_encodeFeature=true&
pvChangeForm%3Apvc_cellInfo=0%2C1&
pvChangeForm%3Apvc%3A0%3Aj_idt127=pvChangeForm%3Apvc%3A0%3Aj_idt127&
pvChangeForm=pvChangeForm&pvChangeForm%3Apvc%3A0%3Aj_idt130=666&
javax.faces.ViewState=-8810553618561534598%3A1979735468348742605

where the important line is the second to last. 666 is the value I put into the cell. It is also displayed if I edit this cell again. But leaving the cell or pressing Enter, it is not saved.

My datatable:

<h:form id="pvChangeForm">
<p:dataTable id="pvc" var="tVar" value="#{paramBean.pvForChange.values}" editable="true" editMode="cell">
    <p:ajax event="cellEdit" listener="#{paramBean.onCellEdit}" update=":pvChangeForm:pvc" />
    <p:column>
        <p:cellEditor>
            <f:facet name="output"><h:outputText value="#{tVar}" /></f:facet>
            <f:facet name="input"><p:inputText value="#{tVar}" style="width:96%" label="Wert"/></f:facet>
        </p:cellEditor>
    </p:column>
</p:dataTable>
</h:form>

paramBean.pvForChange.values is a List<String>. Somehow I have the feeling that the problem lies within this fact (because I want to edit a String in a list directly). But from my understanding, there shouldn't be a problem with that.


Solution

  • Yes, the issue is trying to update a value not wrapped in a POJO. Primefaces datatable are meant to work with the properties wrapped in POJOs, but that said, you can fix your issue using your bean as a wrapping object, like this

        <h:form id="pvChangeForm">
            <p:dataTable id="pvc" var="tVar" value="#{paramBean.pvForChange.values}"  rowIndexVar="index" editable="true" editMode="cell">
                <p:ajax event="cellEdit" listener="#{paramBean.onCellEdit}" update=":pvChangeForm:pvc" />
                <p:column>
                    <p:cellEditor>
                        <f:facet name="output"><h:outputText value="#{paramBean.pvForChange.values[index]}" /></f:facet>
                        <f:facet name="input"><p:inputText value="#{paramBean.pvForChange.values[index]}" style="width:96%" label="Wert"/></f:facet>
                    </p:cellEditor>
                </p:column>
            </p:dataTable>
        </h:form>